File tree Expand file tree Collapse file tree 1 file changed +28
-4
lines changed
yoonexample/src/main/java/deque Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Original file line number Diff line number Diff line change 1
1
package deque ;
2
2
3
+ import exception .EmptyDequeException ;
4
+
3
5
public class LinkedListDeque <E > implements Deque <E > {
4
6
5
7
private int size ;
@@ -46,22 +48,44 @@ public void addLast(E data) {
46
48
47
49
@ Override
48
50
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 ;
50
59
}
51
60
52
61
@ Override
53
62
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 ;
55
71
}
56
72
57
73
@ Override
58
74
public E getFirst () {
59
- return null ;
75
+ if (isEmpty ()) {
76
+ throw new EmptyDequeException ();
77
+ }
78
+
79
+ return this .head .data ;
60
80
}
61
81
62
82
@ Override
63
83
public E getLast () {
64
- return null ;
84
+ if (isEmpty ()) {
85
+ throw new EmptyDequeException ();
86
+ }
87
+
88
+ return this .tail .data ;
65
89
}
66
90
67
91
private static class Node <T > {
You can’t perform that action at this time.
0 commit comments