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