File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed
src/com/anxpp/designpattern/factorymethod Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -11,9 +11,14 @@ public Iterator<T> iterator() {
1111 public boolean add (T t ) {
1212 if (size ==0 ){
1313 first = new Node <T >(t ,null );
14+ size ++;
15+ return true ;
1416 }
15- while (first .next !=null );
16- first .next = new Node <T >(t ,null );
17+ Node <T > node = first ;
18+ while (node .next !=null )
19+ node = node .next ;
20+ node .next = new Node <T >(t ,null );
21+ size ++;
1722 return true ;
1823 }
1924 //链表节点
@@ -33,7 +38,7 @@ private class MyIterator implements Iterator<T>{
3338 }
3439 @ Override
3540 public boolean hasNext () {
36- return next != null ;
41+ return next != null ;
3742 }
3843 @ Override
3944 public T next () {
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ public static void main(String args[]){
1111 }
1212 //获得迭代器
1313 Iterator <Integer > ai = array .iterator ();
14- Iterator <Integer > li = array .iterator ();
14+ Iterator <Integer > li = link .iterator ();
1515 //遍历并输出
1616 while (ai .hasNext ())
1717 System .out .print (ai .next ());
You can’t perform that action at this time.
0 commit comments