한 쪽 끝에서만 자료를 넣고 뺄 수 있는 LIFO(Last In First Out) 형식의 자료 구조
스택은 배열이나 연결리스트로 구현할 수 있으며 Java에서 Stack 클래스 제공
public class Stack {
int top;
int[] stack;
int size;
public Stack(int size) {
top = -1;
stack = new int[size];
this.size = size;
}
public void push(int value) {
stack[++top] = value;
}
public int pop() {
return stack[top--];
}
public int peek() {
return stack[top];
}
public boolean isEmpty() {
if (top < 0) {
return true;
} else {
return false;
}
}
}