File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
yoonexample/src/main/java/stack Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ package stack ;
2
+
3
+ import java .util .EmptyStackException ;
4
+ import list .CircularLinkedList ;
5
+ import list .List ;
6
+
7
+ public class CircularListStack <E > implements Stack <E > {
8
+
9
+ private final List <E > list = new CircularLinkedList <>();
10
+ private int lastIndex = -1 ;
11
+
12
+ @ Override
13
+ public int size () {
14
+ return this .list .size ();
15
+ }
16
+
17
+ @ Override
18
+ public boolean isEmpty () {
19
+ return this .list .isEmpty ();
20
+ }
21
+
22
+ @ Override
23
+ public void push (E data ) {
24
+ this .lastIndex ++;
25
+ this .list .insert (data );
26
+ }
27
+
28
+ @ Override
29
+ public E pop () {
30
+ if (isEmpty ()) {
31
+ throw new EmptyStackException ();
32
+ }
33
+ E tmpData = this .list .remove (lastIndex );
34
+ this .lastIndex --;
35
+ return tmpData ;
36
+ }
37
+
38
+ @ Override
39
+ public E peek () {
40
+ if (isEmpty ()) {
41
+ throw new EmptyStackException ();
42
+ }
43
+ return this .list .get (lastIndex );
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments