맨 마지막 위치에서만 자료를 추가, 삭제, 꺼내올 수 있음(중간의 자료를 꺼낼수는 없다)
LIFO구조(후입선출)
가장 최근의 자료를 찾아오거나 게임에서 히스토리를 유지하고 이를 무를 때 사용할 수 있음
맨 앞에서 자료를 꺼내거나 삭제하고, 맨 뒤에서 자료를 추가 함
FIFO구조(선입선출)
순차적으로 입력된 자료를 순서대로 처리하는데 많이 사용되는 자료구조
stack.push("Apple");
String poppedElement = stack.pop();
System.out.println("Popped Element: " + poppedElement);
String topElement = stack.peek();
System.out.println("Top Element: " + topElement);
boolean isEmpty = stack.isEmpty();
System.out.println("Is Stack Empty? " + isEmpty);
int size = stack.size();
System.out.println("Stack Size: " + size);
queue.add("Apple");
String dequeuedElement = queue.poll();
System.out.println("Dequeued Element: " + dequeuedElement);
String frontElement = queue.peek();
System.out.println("Front Element: " + frontElement);
boolean isEmpty = queue.isEmpty();
System.out.println("Is Queue Empty? " + isEmpty);
int size = queue.size();
System.out.println("Queue Size: " + size);