java - Console to jTextArea1 issue. (voids!?) -


class treetraversal {   public void main(string[] args) throws ioexception   {     system.out.println("displaying tree");     thetree.displaytree(); 

/** how print these kind of things? e.g thetree.preorder(thetree.returnroot()); in jtextarea1 ? */

    stringbuilder order1 = new stringbuilder("inorder traversal: ");     jtextarea1.append("\n"+order1);     //system.out.println("inorder traversal");     thetree.inorder(thetree.returnroot());     //system.out.println(" ");      stringbuilder order2 = new stringbuilder("preorder traversal: ");     jtextarea1.append("\n"+order2);     //system.out.println("preorder traversal");     thetree.preorder(thetree.returnroot());     //system.out.println(" ");      stringbuilder order3 = new stringbuilder("postorder traversal: ");     jtextarea1.append("\n"+order3);     //system.out.println("postorder traversal");     thetree.postorder(thetree.returnroot());     //system.out.println(" ");   } } 

visitor pattern suitable traversing object structures. learn visitor see http://www.oodesign.com/visitor-pattern.html. if complex you, here more understandable visitor in java http://en.wikipedia.org/wiki/visitor_pattern

you have create visitor prints visited node.

to change traversal order can use have (postorder,preorder,inorder) or can make visitor method return value. value should mean noiteration/inorder/preorder/postorder. advantage of can stop/change traversal @ node.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -