Skip to content

Commit 78e278a

Browse files
committed
feat: 덱 삭제, 조회 기능 구현
1 parent a6dd345 commit 78e278a

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

yoonexample/src/main/java/deque/LinkedListDeque.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package deque;
22

3+
import exception.EmptyDequeException;
4+
35
public class LinkedListDeque<E> implements Deque<E> {
46

57
private int size;
@@ -46,22 +48,44 @@ public void addLast(E data) {
4648

4749
@Override
4850
public E removeFirst() {
49-
return null;
51+
if (isEmpty()) {
52+
throw new EmptyDequeException();
53+
}
54+
55+
E data = this.head.data;
56+
this.head = this.head.next;
57+
this.size--;
58+
return data;
5059
}
5160

5261
@Override
5362
public E removeLast() {
54-
return null;
63+
if (isEmpty()) {
64+
throw new EmptyDequeException();
65+
}
66+
67+
E data = this.tail.data;
68+
this.tail = this.tail.prev;
69+
this.size--;
70+
return data;
5571
}
5672

5773
@Override
5874
public E getFirst() {
59-
return null;
75+
if (isEmpty()) {
76+
throw new EmptyDequeException();
77+
}
78+
79+
return this.head.data;
6080
}
6181

6282
@Override
6383
public E getLast() {
64-
return null;
84+
if (isEmpty()) {
85+
throw new EmptyDequeException();
86+
}
87+
88+
return this.tail.data;
6589
}
6690

6791
private static class Node<T> {

0 commit comments

Comments
 (0)