2012년 12월 31일 월요일

[Ch16Ex08] Queue 사용하기

Result

사과
바나나
귤
키위



Sample Code


import java.util.LinkedList;

public class Ch16Ex08 {
public static void main(String[] args) {
LinkedList<String> myQue  = new LinkedList<String>(); //큐 객체 생성
myQue .offer("사과"); //큐에 객체를 추가한다.
myQue .offer("바나나");
myQue .offer("귤");
myQue .offer("키위");
while(myQue .peek()!=null) //현재 큐가 비어있지 않다면
System.out.println(myQue .poll()); //큐에 저장된 객체를 꺼내온다.

// it is not like STACK
}
}


Reference book 이클립스로 배우는 Java 6 Programming/ 임종권, 전병찬/ 가메출판사

댓글 없음:

댓글 쓰기