Skip to content

Commit 80e440a

Browse files
committed
feat: 연결 리스트 기반 큐 dequeue, peek 메소드 구현
1 parent 0d18610 commit 80e440a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

yoonexample/src/main/java/queue/LinkedListQueue.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package queue;
22

3+
import exception.EmptyQueueException;
4+
35
public class LinkedListQueue<E> implements Queue<E> {
46

57
private int size;
@@ -30,12 +32,23 @@ public void enqueue(E data) {
3032

3133
@Override
3234
public E dequeue() {
33-
return null;
35+
if (isEmpty()) {
36+
throw new EmptyQueueException();
37+
}
38+
E retData = this.front.data;
39+
this.front = this.front.next;
40+
this.size--;
41+
42+
return retData;
3443
}
3544

3645
@Override
3746
public E peek() {
38-
return null;
47+
if (isEmpty()) {
48+
throw new EmptyQueueException();
49+
}
50+
51+
return this.front.data;
3952
}
4053

4154
private static class Node<T> {

0 commit comments

Comments
 (0)