-
2. 큐(Queue)[ZB] 2023. 5. 9. 17:44
// 큐(Queue) 기본구조
import java.util.LinkedList;
import java.util.Queue;
public class Main {
public static void main(String[] args) {
Queue queue = new LinkedList();
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
queue.add(5);
System.out.println(queue); //[1, 2, 3, 4, 5]
System.out.println(queue.poll()); // 가장 앞에 있는 1
System.out.println(queue); // 1이 빠진 [2, 3, 4, 5]
System.out.println(queue.peek()); // 가장 앞에 있는 2
System.out.println(queue); // 2가 빠지지 않음 [2, 3, 4, 5]
System.out.println(queue.contains(3));
System.out.println(queue.size());
System.out.println(queue.isEmpty());
queue.clear();
System.out.println(queue);
System.out.println(queue.poll()); // 비어 있는 상태에서 poll출력 ==> null
}
}'[ZB]' 카테고리의 다른 글
6. 비선형자료구조 - 힙(heap) (0) 2023.05.13 5. 연결리스트(Linked List) (0) 2023.05.12 4. HashMap (0) 2023.05.11 3.배열 (0) 2023.05.10 1. 스택(Stack) (0) 2023.05.08