Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (ajprincess):

Pls help.:) I want someone to explain me this method statement by statement.

OpenStudy (ajprincess):

public void displayTree() { Stack Stack1=new Stack(); Stack1.push(root); int nBlanks = 32; boolean isRowEmpty = false; System.out.println("..............................................................."); while(isRowEmpty==false) { Stack Stack2 = new Stack(); isRowEmpty = true; for(int j=0; j<nBlanks; j++) { System.out.print(' '); } while(Stack1.isEmpty()==false) { Node temp=(Node)Stack1.pop(); if(temp!=null) { System.out.print(temp.Data); Stack2.push(temp.leftChild); Stack2.push(temp.rightChild); if(temp.leftChild!=null || temp.rightChild!=null) { isRowEmpty=false; } }else { System.out.print("-"); System.out.print("-"); Stack2.push(null); Stack2.push(null); } for(int j=0; j<nBlanks*2-2;j++) { System.out.print(' '); } } System.out.println(); nBlanks/=2; while(Stack2.isEmpty()==false) { Stack1.push(Stack2.pop()); } } System.out.println("................................................................"); } }

OpenStudy (ajprincess):

@e.mccormick

OpenStudy (ajprincess):

if u dnt mind can u pls give me links where can I find an explanation of this method.

OpenStudy (e.mccormick):

Well, I am not sure what it is from, and they did not document it. From the name, I would guess it is meant to print out something based on a binary tree. It is public, so things in it could be used by others.... but exactly how it would be used depends on what it was written to work with. I am just starting to learn Java myself. I know a good deal of C++, which is similar. The stack is a sort of last in first out data type, so the data is ordered in that way. Past that, I would have to build some sort of test harness to see what it gave me.

OpenStudy (ajprincess):

hmm k. thanx a lot for tryng to help me.

OpenStudy (e.mccormick):

How the stack itself works: http://introcs.cs.princeton.edu/java/43stack/ But when I search for Node as a data type, I don't get a standard reference, so I am not sure what the nodes are that it is putting on this stack.

OpenStudy (e.mccormick):

Ah, changed my search a little and got this on nodes: http://docs.oracle.com/javase/6/docs/api/org/w3c/dom/Node.html

OpenStudy (ankit042):

This looks like a pre-order traversal to me...have to check it though

OpenStudy (ajprincess):

@hba

OpenStudy (hba):

|dw:1378481510018:dw|

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!