File tree Expand file tree Collapse file tree 13 files changed +136
-52
lines changed
group05/1094051862/test01/src/com Expand file tree Collapse file tree 13 files changed +136
-52
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 1
- package com .coding1094051862 .basic ;
1
+ package com .coding .basic ;
2
2
3
3
import org .junit .Assert ;
4
4
import org .junit .Test ;
@@ -7,7 +7,7 @@ public class ArrayListTest {
7
7
8
8
@ Test
9
9
public void test () {
10
- ArrayList list = new ArrayList ();
10
+ List list = new ArrayList ();
11
11
for (int i = 0 ; i < 10 ; i ++) {
12
12
list .add (i );
13
13
}
@@ -18,6 +18,14 @@ public void test() {
18
18
Assert .assertEquals (12 , list .size ());
19
19
Assert .assertEquals (99 , list .remove (3 ));
20
20
Assert .assertEquals (11 , list .size ());
21
+ Iterator iterator = list .iterator ();
22
+ for (int i = 0 ; i < list .size (); i ++) {
23
+ System .out .println (list .get (i ));
24
+ }
25
+ System .out .println ("======" );
26
+ while (iterator .hasNext ()) {
27
+ System .out .println (iterator .next ());
28
+ }
21
29
}
22
30
23
31
}
Original file line number Diff line number Diff line change 1
- package com .coding1094051862 .basic ;
1
+ package com .coding .basic ;
2
2
3
3
public class BinaryTreeNode {
4
4
Original file line number Diff line number Diff line change 1
- package com .coding1094051862 .basic ;
1
+ package com .coding .basic ;
2
2
3
3
public interface Iterator {
4
4
public boolean hasNext ();
Original file line number Diff line number Diff line change 1
- package com .coding1094051862 .basic ;
1
+ package com .coding .basic ;
2
2
3
3
public class LinkedList implements List {
4
4
@@ -114,16 +114,23 @@ public Object removeLast(){
114
114
}
115
115
public Iterator iterator (){
116
116
return new Iterator () {
117
+ int cusor = 0 ;
118
+ Node current = head ;
117
119
@ Override
118
120
public Object next () {
119
- // TODO Auto-generated method stub
120
- return null ;
121
+ if (!hasNext ()) {
122
+ System .out .println ("next : !hasNext" );
123
+ return null ;
124
+ }
125
+ Object o = current .data ;
126
+ current = current .next ;
127
+ cusor ++;
128
+ return o ;
121
129
}
122
130
123
131
@ Override
124
132
public boolean hasNext () {
125
- // TODO Auto-generated method stub
126
- return false ;
133
+ return cusor < size ;
127
134
}
128
135
};
129
136
}
Original file line number Diff line number Diff line change 1
- package com .coding1094051862 .basic ;
1
+ package com .coding .basic ;
2
2
3
3
import junit .framework .Assert ;
4
4
@@ -27,6 +27,10 @@ public void test() {
27
27
Assert .assertEquals (3 , list .get (5 ));
28
28
Assert .assertEquals (4 , list .get (6 ));
29
29
Assert .assertEquals (800 , list .get (8 ));
30
+ Iterator iterator = list .iterator ();
31
+ while (iterator .hasNext ()) {
32
+ System .out .println (iterator .next ());
33
+ }
30
34
}
31
35
32
36
}
Original file line number Diff line number Diff line change 1
- package com .coding1094051862 .basic ;
1
+ package com .coding .basic ;
2
2
3
3
public interface List {
4
4
public void add (Object o );
5
5
public void add (int index , Object o );
6
6
public Object get (int index );
7
7
public Object remove (int index );
8
8
public int size ();
9
+ public Iterator iterator ();
9
10
}
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class Queue {
4
+ private List list = new ArrayList ();
5
+ private int size = 0 ;
6
+ public void enQueue (Object o ){
7
+ list .add (o );
8
+ size ++;
9
+ }
10
+
11
+ public Object deQueue (){
12
+ if (size == 0 )
13
+ return null ;
14
+ size --;
15
+ return list .remove (0 );
16
+ }
17
+
18
+ public boolean isEmpty (){
19
+ return size == 0 ;
20
+ }
21
+
22
+ public int size (){
23
+ return size ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ import static org .junit .Assert .*;
4
+ import junit .framework .Assert ;
5
+
6
+ import org .junit .Test ;
7
+
8
+ import sun .org .mozilla .javascript .internal .ast .NewExpression ;
9
+
10
+ public class QueueTest {
11
+
12
+ @ Test
13
+ public void test () {
14
+ Queue queue = new Queue ();
15
+ for (int i = 0 ; i < 100 ; i ++) {
16
+ queue .enQueue (i );
17
+ }
18
+ Assert .assertEquals (100 , queue .size ());
19
+ for (int i = 0 ; i < 100 ; i ++) {
20
+ Assert .assertEquals (i , queue .deQueue ());
21
+ }
22
+ Assert .assertEquals (0 , queue .size ());
23
+
24
+ }
25
+
26
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class Stack {
4
+ private List elementData = new ArrayList ();
5
+ private int size = 0 ;
6
+ public void push (Object o ){
7
+ elementData .add (o );
8
+ size ++;
9
+ }
10
+
11
+ public Object pop (){
12
+ if (size == 0 )
13
+ return null ;
14
+ return elementData .remove (--size );
15
+ }
16
+
17
+ public Object peek (){
18
+ if (size == 0 )
19
+ return null ;
20
+ return elementData .get (size - 1 );
21
+ }
22
+ public boolean isEmpty (){
23
+ return size == 0 ;
24
+ }
25
+ public int size (){
26
+ return size ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ import static org .junit .Assert .*;
4
+ import junit .framework .Assert ;
5
+
6
+ import org .junit .BeforeClass ;
7
+ import org .junit .Test ;
8
+
9
+ public class StackTest {
10
+
11
+ @ Test
12
+ public void test () {
13
+ Stack stack = new Stack ();
14
+ for (int i = 0 ; i < 100 ; i ++) {
15
+ stack .push (i );
16
+ }
17
+ Assert .assertEquals (100 , stack .size ());
18
+ Assert .assertEquals (99 , stack .pop ());
19
+ for (int i = 98 ; i >= 0 ; i --) {
20
+ Assert .assertEquals (i , stack .peek ());
21
+ Assert .assertEquals (i , stack .pop ());
22
+ }
23
+ Assert .assertEquals (0 , stack .size ());
24
+ }
25
+
26
+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments