반응형

이 게시물은 다음 링크를 참조하여 학습했습니다.

 

Queue (Java Platform SE 7 )

A collection designed for holding elements prior to processing. Besides basic Collection operations, queues provide additional insertion, extraction, and inspection operations. Each of these methods exists in two forms: one throws an exception if the opera

docs.oracle.com

 

Deque (Java Platform SE 7 )

A linear collection that supports element insertion and removal at both ends. The name deque is short for "double ended queue" and is usually pronounced "deck". Most Deque implementations place no fixed limits on the number of elements they may contain, bu

docs.oracle.com

 

PriorityQueue (Java Platform SE 7 )

An unbounded priority queue based on a priority heap. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. A priority queue does

docs.oracle.com

 

[Java] Deque (덱/데크) 사용법 및 예제

Deque(덱/데크) 덱은 Double-Ended Queue의 줄임말로 큐의 양쪽에 데이터를 넣고 뺄 수 있는 형태의 자료구조를 의미한다. 하나의 자료구조에 큐(Queue)와 스택(Stack)을 합쳐 놓은 형태라고 생각하면 된다.

hbase.tistory.com

 

[Java] PriorityQueue(우선순위 큐) 클래스 사용법 & 예제 총정리

우선순위 큐(Priority Queue)란? 일반적으로 큐는 데이터를 일시적으로 쌓아두기 위한 자료구조로 스택과는 다르게 FIFO(First In First Out)의 구조 즉 먼저 들어온 데이터가 먼저 나가는 구조를 가집니다

coding-factory.tistory.com

1. Queue?

queue는 FIFO(First-In-First-Out)의 형태를 갖는 자료구조이다.

쉽게 생각하면 한 방향으로 갈 수 있는 터널을 생각하면 된다. 

들어갈때는 뒤에서 들어가고, 나올때는 앞에서 나오면서 가장 먼저 들어간 값이 가장 먼저 나온다.

queue를 사용하려면 아래처럼 사용하면 된다.

1
Queue<Integer> Q = new LinkedList<>();
cs

 

1-1. 메서드

이번 게시물에서는 내가 자주 사용하는 멤버함수만 정리했다.

(1) boolean offer(E e)

Queue에 e를 넣어준다

 

(2) E peek()

Queue에서 최앞단 값을 반환한다

 

(3) E poll()

Queue에서 최앞단 값을 제거 후 반환한다.

 

(4) int size()

Queue의 사이즈를 반환한다

 

(5) boolean isEmpty()

Queue가 비어있는지 확인한다

 

2. Deque?

deque는 Double ended queue의 약자로, 한국말로 해석하면 "양방향 큐"이다.

큐의 삽입/삭제가 한방향만 가능한것에 반해, 덱은 양방향 삽입/삭제가 가능하다.

deque를 사용하려면 아래처럼 사용하면 된다.

1
Deque<Integer> DQ = new LinkedList<>();
cs
 

2-1. 메서드

이번 게시물에서는 내가 자주 사용하는 멤버함수만 정리했다.

(1) boolean offerFirst(E e)

Deque의 첫번째에 e를 넣어준다

 

(2) boolean offerLast(E e)

Deque의 마지막에 e를 넣어준다

 

(3) E peekFirst()

Deque의 첫번째 값을 반환한다

 

(4) E peekLast()

Deque의 마지막 값을 반환한다

 

(5) E pollFirst()

Deque의 첫번째 값을 제거 후 반환한다

 

(6) E pollLast()

Deque의 마지막 값을 제거 후 반환한다

 

(7) int size()

Deque의 사이즈를 반환한다

 

(8) boolean isEmpty()

Deque이 비어있는지 확인한다

 

3. PriorityQueue?

PriorityQueue는 우리말로 하면 "우선순위 큐"이다. 

우선순위 큐를 사용하면 모든 원소중에 가장 큰/작은 값이 peek()에 위치하도록 할 수 있다.

Heap자료구조를 프로그래밍적으로 사용하는 것이라 생각하면 이해가 쉽다.

PriorityQueue는 아래처럼 사용한다!

1
2
PriorityQueue<Integer> PQ = new PriorityQueue<>();                            // default 오름차순
PriorityQueue<Integer> PQ = new PriorityQueue<>(Collections.reverseOrder());// 
cs

 

3-1. 멤버함수

이번 게시물에서는 내가 자주 사용하는 멤버함수만 정리했다.

(1) boolean offer(E e)

PriorityQueue에 e를 삽입한다

 

(2) E peek()

PriorityQueue의 제일 큰/작은 값을 반환한다

 

(3) E poll()

PriorityQueue에 제일 큰/작은 값을 제거 후 반환한다

 

(4) int size()

PriorityQueue의 사이즈를 반환한다

 

(5) boolean isEmpty()

PriorityQueue가 비어있는지 확인한다

반응형

'Legacy' 카테고리의 다른 글

[Kotlin #2] 고급문법  (0) 2022.05.11
[Kotlin #1] 기본문법  (0) 2022.05.11
[Java#6] Stack  (0) 2022.05.04
[Java#5] Set, HashSet, TreeSet  (0) 2022.05.03
[Java#4] Map, HashMap, TreeMap  (0) 2022.05.03

+ Recent posts