Question: Need help writing a Java program! It is supposed to a tree that holds and displays a string in all capital letters. Instructions, and sample

Need help writing a Java program! It is supposed to a tree that holds and displays a string in all capital letters. Instructions, and sample code, were given and are displayed below. Any help is appreciated!

Here are the steps when we encounter an operand: 1. Make a tree with one node that holds the operand. 2. Push this tree onto the stack.

Here are the steps when we encounter an operator: 1. Pop two operand trees B and C off the stack. 2. Create a new tree A with the operator in its root. 3. Attach B as the right child of A. 4. Attach C as the left child of A. 5. Push the resulting tree back on the stack.

public void displayTree() { Stack globalStack = new Stack(); globalStack.push(root); int nBlanks = 32; boolean isRowEmpty = false; System.out.println( "......................................................"); while(isRowEmpty==false) { Stack localStack = new Stack(); isRowEmpty = true;

for(int j=0; j

while(globalStack.isEmpty()==false) { Node temp = (Node)globalStack.pop(); if(temp != null) { System.out.print(temp.iData); localStack.push(temp.leftChild); localStack.push(temp.rightChild);

if(temp.leftChild != null || temp.rightChild != null) isRowEmpty = false; } else { System.out.print("--"); localStack.push(null); localStack.push(null); } for(int j=0; j

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!