1. 스택
- 삽입과 삭제 연산이 후입선출로 이뤄지는 자료구조
2. 큐
- 삽입과 삭제 연산이 선입선출로 이뤄지는 자료구조
3. 스택과 큐 코드 구현
public class Example {
public static void main(String[] args) {
Stack st = new Stack();
Queue q = new LinkedList(); //Queue의 인터페이스 구현체인 LinkedList를 사용
st.push("0");
st.push("1");
st.push("2");
q.offer("0");
q.offer("1");
q.offer("2");
System.out.println("=== Stack ===");
while(!st.isEmpty()) {
System.out.println(st.pop());
}
System.out.println("=== Queue ===");
while(!q.isEmpty()) {
System.out.println(q.poll());
}
}
}