* Programming/JAVA
DAY22 큐&스택
고경a
2016. 8. 4. 11:55
22일차 강의 정리
1. 큐(Queue)
선입선출(FIFO: First in First out) - interface
2. 스택(Stack)
후입선출(LIFO: Last in First out) - class
소스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public static void main(String[] args) { Queue que = new LinkedList(); que.offer("첫째"); //마지막 요소로 추가 que.offer("둘째"); que.offer("셋째"); que.offer("넷째"); while(que.isEmpty()==false){ System.out.println(que.poll()); //첫번째 값 꺼내오기 // System.out.println(que.peek()); //꺼내지 않고 확인만 } System.out.println("-------------------------------"); Stack st = new Stack(); st.push("하나"); st.push("두울"); st.push("세엣"); st.push("네엣"); while(st.isEmpty()==false){ System.out.println(st.pop()); //마지막부터 꺼내오기 // System.out.println(st.peek()); //꺼내지 않고 확인만 } } | cs |
결과