Skip to content

Commit ad1d702

Browse files
committed
add queue and stack
1 parent 43fc716 commit ad1d702

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

group03/619224754/src/com/coding/basic/Queue.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
public class Queue {
44

5-
public void enQueue(Object o){
5+
private LinkedList list = new LinkedList();
6+
7+
public void enQueue(Object o){
8+
list.addLast(o);
69
}
710

811
public Object deQueue(){
9-
return null;
12+
Object ret = list.removeFirst();
13+
return ret;
1014
}
1115

1216
public boolean isEmpty(){
13-
return false;
17+
return list.size() == 0;
1418
}
1519

1620
public int size(){
17-
return -1;
21+
return list.size();
1822
}
1923
}

group03/619224754/src/com/coding/basic/Stack.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ public class Stack {
44
private ArrayList elementData = new ArrayList();
55

66
public void push(Object o){
7+
this.elementData.add(o);
78
}
89

910
public Object pop(){
10-
return null;
11+
Object ret = this.elementData.remove(this.elementData.size() - 1);
12+
return ret;
1113
}
1214

1315
public Object peek(){
16+
Object ret = this.elementData.get(this.elementData.size() - 1);
1417
return null;
1518
}
1619
public boolean isEmpty(){
17-
return false;
20+
return this.elementData.size() == 0;
1821
}
1922
public int size(){
20-
return -1;
23+
return this.elementData.size();
2124
}
2225
}

0 commit comments

Comments
 (0)