Skip to content

Commit c3eeed7

Browse files
committed
实现 Queue
1 parent 3c5c6f1 commit c3eeed7

File tree

3 files changed

+90
-29
lines changed

3 files changed

+90
-29
lines changed
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package com.coding.basic;
22

33
public class Queue {
4-
5-
public void enQueue(Object o){
6-
}
7-
8-
public Object deQueue(){
9-
return null;
10-
}
11-
12-
public boolean isEmpty(){
13-
return false;
14-
}
15-
16-
public int size(){
17-
return -1;
18-
}
4+
5+
private ArrayList elementData = new ArrayList();
6+
private int size = 0;
7+
8+
public void enQueue(Object o) {
9+
elementData.add(o);
10+
size++;
11+
}
12+
13+
public Object deQueue() {
14+
return elementData.remove(0);
15+
}
16+
17+
public boolean isEmpty() {
18+
return size == 0;
19+
}
20+
21+
public int size() {
22+
return size;
23+
}
1924
}

group04/24658892/learnjava/src/test/java/com/coding/basic/ArrayListTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.coding.basic;
22

3+
import org.junit.Assert;
34
import org.junit.Test;
45

5-
import static org.junit.Assert.assertEquals;
6-
76
public class ArrayListTest {
87

98
@Test
@@ -17,7 +16,7 @@ public void add() throws Exception {
1716
data.add(i);
1817
}
1918
for (int i = 0; i < size; i++) {
20-
assertEquals(i, data.get(i));
19+
Assert.assertEquals(i, data.get(i));
2120
}
2221
//size > 100
2322
data = new ArrayList();
@@ -26,7 +25,7 @@ public void add() throws Exception {
2625
data.add(i);
2726
}
2827
for (int i = 0; i < size; i++) {
29-
assertEquals(i, data.get(i));
28+
Assert.assertEquals(i, data.get(i));
3029
}
3130
//size = 100
3231
data = new ArrayList();
@@ -35,7 +34,7 @@ public void add() throws Exception {
3534
data.add(i);
3635
}
3736
for (int i = 0; i < size; i++) {
38-
assertEquals(i, data.get(i));
37+
Assert.assertEquals(i, data.get(i));
3938
}
4039
}
4140

@@ -57,14 +56,14 @@ public void add1() throws Exception {
5756
for (int i = 0; i < data.size(); i++) {
5857
if (i == index) {
5958
b = true;
60-
assertEquals(index + 10000, data.get(i));
59+
Assert.assertEquals(index + 10000, data.get(i));
6160
}
6261
else {
6362
if (b) {
64-
assertEquals(i - 1, data.get(i));
63+
Assert.assertEquals(i - 1, data.get(i));
6564
}
6665
else {
67-
assertEquals(i, data.get(i));
66+
Assert.assertEquals(i, data.get(i));
6867
}
6968
}
7069
}
@@ -76,7 +75,7 @@ public void get() throws Exception {
7675
data.add(1);
7776
data.add(2);
7877
data.add(3);
79-
assertEquals(2, data.get(1));
78+
Assert.assertEquals(2, data.get(1));
8079
}
8180

8281
@Test
@@ -86,9 +85,9 @@ public void remove() throws Exception {
8685
data.add(2);
8786
data.add(3);
8887
data.remove(1);
89-
assertEquals(2, data.size());
90-
assertEquals(1, data.get(0));
91-
assertEquals(3, data.get(1));
88+
Assert.assertEquals(2, data.size());
89+
Assert.assertEquals(1, data.get(0));
90+
Assert.assertEquals(3, data.get(1));
9291
}
9392

9493
@Test
@@ -97,7 +96,7 @@ public void size() throws Exception {
9796
data.add(1);
9897
data.add(1);
9998
data.add(1);
100-
assertEquals(3, data.size());
99+
Assert.assertEquals(3, data.size());
101100
}
102101

103102
@Test
@@ -109,7 +108,7 @@ public void iterator() throws Exception {
109108
Iterator iterator = data.iterator();
110109
int i = 0;
111110
while (iterator.hasNext()) {
112-
assertEquals(++i, iterator.next());
111+
Assert.assertEquals(++i, iterator.next());
113112
}
114113
}
115114
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.coding.basic;
2+
3+
import org.junit.Test;
4+
5+
public class LinkedListTest {
6+
7+
@Test
8+
public void add() throws Exception {
9+
10+
}
11+
12+
@Test
13+
public void add1() throws Exception {
14+
15+
}
16+
17+
@Test
18+
public void get() throws Exception {
19+
20+
}
21+
22+
@Test
23+
public void remove() throws Exception {
24+
25+
}
26+
27+
@Test
28+
public void size() throws Exception {
29+
30+
}
31+
32+
@Test
33+
public void addFirst() throws Exception {
34+
35+
}
36+
37+
@Test
38+
public void addLast() throws Exception {
39+
40+
}
41+
42+
@Test
43+
public void removeFirst() throws Exception {
44+
45+
}
46+
47+
@Test
48+
public void removeLast() throws Exception {
49+
50+
}
51+
52+
@Test
53+
public void iterator() throws Exception {
54+
55+
}
56+
57+
}

0 commit comments

Comments
 (0)