mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 03:05:24 +08:00
* feat(ko): add the complete Korean online edition * Use UTF-8 for Python CI output on Windows * Remove print-book promotion from the Korean site * fix(ko): preserve emphasis before Korean particles
41 lines
1.1 KiB
Java
41 lines
1.1 KiB
Java
/**
|
|
* File: queue.java
|
|
* Created Time: 2022-11-25
|
|
* Author: krahets ([email protected])
|
|
*/
|
|
|
|
package chapter_stack_and_queue;
|
|
|
|
import java.util.*;
|
|
|
|
public class queue {
|
|
public static void main(String[] args) {
|
|
/* 큐 초기화 */
|
|
Queue<Integer> queue = new LinkedList<>();
|
|
|
|
/* 큐에 원소 삽입 */
|
|
queue.offer(1);
|
|
queue.offer(3);
|
|
queue.offer(2);
|
|
queue.offer(5);
|
|
queue.offer(4);
|
|
System.out.println("큐 queue = " + queue);
|
|
|
|
/* 맨 앞 원소 접근 */
|
|
int peek = queue.peek();
|
|
System.out.println("맨 앞 원소 peek = " + peek);
|
|
|
|
/* 큐에서 원소 꺼내기 */
|
|
int pop = queue.poll();
|
|
System.out.println("큐에서 꺼낸 원소 pop = " + pop + ", 큐에서 꺼낸 후 queue = " + queue);
|
|
|
|
/* 큐의 길이 반환 */
|
|
int size = queue.size();
|
|
System.out.println("큐 길이 size = " + size);
|
|
|
|
/* 큐가 비어 있는지 판단 */
|
|
boolean isEmpty = queue.isEmpty();
|
|
System.out.println("큐가 비어 있는가 = " + isEmpty);
|
|
}
|
|
}
|