File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
group05/284422826/src/com/github/zhanglifeng/coding2017/basic Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com .github .zhanglifeng .coding2017 .basic ;
2
2
3
+ import java .util .EmptyStackException ;
4
+
3
5
public class Queue {
4
6
private LinkedList elementData = new LinkedList ();
5
7
public void enQueue (Object o ){
6
8
elementData .add (o );
7
9
}
8
10
9
11
public Object deQueue (){
12
+ if (elementData .size () == 0 ) {
13
+ throw new EmptyStackException ();
14
+ }
10
15
return elementData .removeFirst ();
11
16
}
12
17
Original file line number Diff line number Diff line change 1
1
package com .github .zhanglifeng .coding2017 .basic ;
2
2
3
+ import java .util .EmptyStackException ;
4
+
3
5
public class Stack {
4
6
private ArrayList elementData = new ArrayList ();
5
7
@@ -8,10 +10,16 @@ public void push(Object o){
8
10
}
9
11
10
12
public Object pop (){
13
+ if (elementData .size () == 0 ) {
14
+ throw new EmptyStackException ();
15
+ }
11
16
return elementData .remove (elementData .size () - 1 );
12
17
}
13
18
14
19
public Object peek (){
20
+ if (elementData .size () == 0 ) {
21
+ throw new EmptyStackException ();
22
+ }
15
23
return elementData .get (elementData .size () - 1 );
16
24
}
17
25
public boolean isEmpty (){
You can’t perform that action at this time.
0 commit comments