A root-to-leaf path in a tree is defined to be a sequence of nodes starting from the root node and proceeding downwards to a leaf.

Required that given a tree, output the tree after reversing all root-to-leaf paths.

For the following tree:

root = 5

root.right = 8, root.left = 4

root.right.right = 4, root.right.left = 13, root.left.left = 11

root.right.left.right = 1, root.left.left.right = 2, root.left.left.left = 7

The output tree is:

root = 4

root.right = 13, root.left = 4

root.right.right = 1, root.right.left = 8, root.left.left = 11

root.right.left.right = 2, root.left.left.right = 7, root.left.left.left = 5

I think it would be useful to use linked lists to store the paths, but the code I wrote doesn't work and I don't know what its problem is.

Any suggestions?

Thanks in advance.

Related Tutorials/Questions & Answers:

**tree in java**
tree in java Can you help me to draw the

tree? First we assign the parent node. when child node(x) come we must check the condition. there are three condition such as x<5,5<=x<10 and 10<=x<15 after that we have

Advertisements

**tree in java**
average of children. Like following

tree.
(3+7+12)/3=7(

root...

tree in java Can you help me to draw the

tree? First we assign the parent node. when child node(x) come we must check the condition. there are three

**tree in java**
average of children. Like following

tree.
(3+7+12)/3=7(

root...

tree in java Can you help me to draw the

tree? First we assign the parent node. when child node(x) come we must check the condition. there are three

**tree in java**
average of children. Like following

tree.
(3+7+12)/3=7(

root...

tree in java Can you help me to draw the

tree? First we assign the parent node. when child node(x) come we must check the condition. there are three

**java tree expressions - XML**
java tree expressions hi

all,
i have a problem in

tree expressions.
see there is a document

tree like a parent document has no. of child... code to solve the problem and visit to :
http://www.roseindia.net/

java
**identify the paths**
identify the paths write a srcipt for cutting only the

paths of the file present inside a directory or folder
Hi Friend,
Please clarify either you want to get the name of the file from the given path or you want

**reversing a string**
reversing a string how to reverse a string without using string function
class ReverseString
{
public static void main(String[] args)
{
String str="Hello World";
String st[]=str.split

**tree view - Java Beginners**
tree view I want to use

tree view in my example code to display data... visit the following links:
http://www.roseindia.net/

java/example/

java/swing/TreeComponent.shtml
http://www.roseindia.net/

java/example/

java/swing

**Java tree map trouble**
Java tree map trouble This is a project for a class, and I am totally stuck! I've created a

tree map using an input text file. I split the lines...);
// Create keyMap with

all keys and values
Set<String> keySet

**tree view - Java Beginners**
tree view Hello Deepak,
Thanks for your help last time regarding

java.
I have another problem, Actually I want a

tree...
Hi Friend,
You are using jsp or

java swing. Please clarify this.
Do

**B+ tree - Java Beginners**
(){

Tree root;
boolean bool;
int nti;

root = new

Tree();
bool = root.Init....
In this assignment, you will implement B+-

tree data structure on a fixed-length data... automatically or manually.

All fields are fixed length: 8 for number (20022509

**tree view - Java Beginners**
tree view
I m using swing for the treeview in my application and also the database(Hsqldb).
I want to connect the

tree view with the database fields.
If u want more clarification ,let me know.
Thanks

**Tree**
Tree print("code sample");1) Write

Java code to create the following

tree using new

Tree state-
ments:
1

**B+tree lodaing - Java Beginners**
B+

tree lodaing hi, i have fixed-length data file such student table.

All fields are fixed length: 8 for number (20022509), 3 for name (PIS), 4... or delimited by a white space.
how i can Initially, constructed B+

tree based

**Question on reversing word of a sentnce**
Question on

reversing word of a sentnce Write a function that accepts a sentence as a parameter, and returns the same with each of its words reversed. The returned sentence should have 1 blank space between each pair of words

**Tree View with database - Java Beginners**
Tree View with database
Hi,
I'm working with Swing.I have...);
JTree

tree = new JTree(parent);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_

TREE_SELECTION

**Java binary tree insert**
Java binary

tree insert
.... The concept lies
behind is that

all the element value less than the

root node... node insert right
to this

root node.
This module implements a binary search

tree
**drawing a christmas tree - Java Beginners**
drawing a christmas tree how do i write a program that draws a chrimas

tree using the knowledge of loops only. i.e * *** ***** ******* the program will draw a Christ mas tree Hi ChristmasTree.javaimport java.awt.

**tree**
tree hi.i want search in bstree . what am i doing?
Please visit the following link:
http://www.roseindia.net/tutorial/

java/core/binarySearch.html

**Spanning Tree**
Spanning Tree hii,
What is a spanning

Tree?
hello,
A spanning

tree is a

tree associated with a network.

All the nodes of the graph appear on the

tree once. A minimum spanning

tree is a spanning

tree organized so

**Use a tree stack to sort number in java?**
Use a

tree stack to sort number in

java? The Question is :
Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers

**Use a tree stack to sort number in java?**
Use a

tree stack to sort number in

java? The Question is :
Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers

**Use a tree stack to sort number in java?**
Use a

tree stack to sort number in

java? The Question is :
Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers

**Use a tree stack to sort number in java?**
Use a

tree stack to sort number in

java? The Question is :
Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers

**Use a tree stack to sort number in java?**
Use a

tree stack to sort number in

java? The Question is :
Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers

**Use a tree stack to sort number in java?**
Use a

tree stack to sort number in

java? The Question is :
Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers

**Tree Grid using JSF - Java Server Faces Questions**
Tree Grid using JSF Hi

All,
I am using Trinidad TLD for JSF.
I have implemented simple table, but having problem with

Tree grid using same.
I have read

all document on Trinidad site for

Tree grid, but they didn't mention

**binary tree**
://www.roseindia.net/

java/

java-get-example/

java-binary-

tree-code.shtml
http://www.roseindia.net/

java/

java-get-example/

java-binary-

tree-insert.shtml...binary tree can a binary

tree be implemented with out comparing