Subversion Repositories programming

Rev

Rev 23 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23 Rev 24
Line 56... Line 56...
56
			printPostOrderHelper( ps, (UnorderedTree)it.next() );
56
			printPostOrderHelper( ps, (UnorderedTree)it.next() );
57
		}
57
		}
58
		ps.print( tree.root + " "); //print the node
58
		ps.print( tree.root + " "); //print the node
59
	}
59
	}
60
 
60
 
-
 
61
	public void printLevelOrder( PrintStream ps ) {
-
 
62
		Queue q = new Queue();
-
 
63
 
-
 
64
		q.enqueue(this); //add the root
-
 
65
		
-
 
66
		while( !q.isEmpty() ) {
-
 
67
 			//remove the first item in the queue
-
 
68
			UnorderedTree temp = (UnorderedTree)q.dequeue();
-
 
69
 
-
 
70
			ps.print(temp.root + " "); //visit the node
-
 
71
 
-
 
72
			//add all the children of temp to the queue
-
 
73
			for( Iterator it=temp.subtrees.iterator(); it.hasNext(); ) {
-
 
74
				q.enqueue( it.next() );
-
 
75
			}
-
 
76
		}
-
 
77
		ps.println(); //end the current line
-
 
78
	}
61
 
79
 
62
	
-
 
63
} //end class UnorderedTree
80
} //end class UnorderedTree
64
 
81