Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

If possible, shake hands.

Answered: 1 week ago