project: tool started
[tu-mathvis-ws13:matsols-tu-mathvis-ws13.git] / src / student1522 / project / PolyaTreeIterator.java
1 package student1522.project;
2
3 public class PolyaTreeIterator {
4         
5         public PolyaTreeNode currNode;
6         
7         private PolyaTree tree;
8         
9         private int index;
10         
11         public PolyaTreeIterator( PolyaTree tree ){
12                 this.currNode = tree.nodes.getFirst();
13                 this.tree = tree;
14                 this.index = 0;
15         }
16         
17         public void next(){
18                 index++;
19                 if ( !this.isAtEnd() ){
20                         this.currNode = tree.nodes.get(index);
21                 }
22                 else{
23                         index--;
24                 }
25                 
26         }
27         
28         
29         public void reset(){
30                 this.currNode = tree.nodes.getFirst();
31                 index = 0;
32         }
33         
34         public boolean isAtEnd(){
35                 return this.tree.getSize() == index;
36         }
37
38         public static void main(String[] args) {
39                 PolyaMagic magic = new PolyaMagic( 2, new int[]{1,1,2}, false);
40                 PolyaTreeIterator iter = new PolyaTreeIterator( magic.orbits.get(4) );
41                 while( !iter.isAtEnd() ){
42                         iter.next();
43                 }
44                 
45         }
46
47 }