스택 소스코드: 두 판 사이의 차이
IT위키
(새 문서: == Java == <syntaxhighlight lang='java' line='line'> public class Stack { private int MAX = 5; private int top; private int[] item; public Stack() { top = 0; item = new in...) |
(차이 없음)
|
2018년 5월 6일 (일) 13:03 판
Java
public class Stack {
private int MAX = 5;
private int top;
private int[] item;
public Stack() {
top = 0;
item = new int[MAX];
}
public void push(int num) {
if(top >= item.length) {
System.out.println("Stack is fulled");
return ;
} else {
item[top] = num;
top = top + 1;
System.out.println(num);
}
}
public void pop() {
if(top == 0) {
System.out.println("Stack is empty");
} else {
top = top - 1;
int num;
num = item[top];
item[top] = 0;
System.out.println(num);
}
}
}