Devam Ediyor

Non-recursive Binary Tree Traversal Program in Java

I need a program written in java, that outputs the result using console not a GUI, it must meet the following requirements:

The program must allow to traverse a binary tree which is created using n ramdom elements, allowing to print the methods "inorder", "preorder", and "postorder".

It can be made using stacks, linked list stacks, nodes, or whatever other method you prefer.

The traversals should have two variations, one using "for loops", and another using "while loops". for a total of 6 nonrecursive methods:

inorderWhileLoop

preorderWhileLoop

postorderWhileLoop

inorderForeLoop

preorderForLoop

postorderForLoop

The binary tree should be created using "n" number of random elements, number which is asked to the user at very run of the program.

The program should be fully commented, and documented so I can understand how it works, should be written using Netbeans IDE 7.3 and the latest JDK.

I will provide a working program which has the recursive methods implemented and console menu, creates the binary tree and prints the recursive methods.

Here is the current output:

==========================================

| BINARY TREES |

==========================================

| Create a binary tree using n random numbers. |

| Choose an Option |

| Options: |

| 1. While Loop - recursive |

| 2. For Loop - recursive |

==========================================

Select an option: 1

Option 1 selected While Loop - recursive

Enter the total number of random elements:

12

92 11 65 98 42 75 29 35 73 31 93 81

Inorder.

11 -> 29 -> 31 -> 35 -> 42 -> 65 -> 73 -> 75 -> 81 -> 92 -> 93 -> 98 ->

*****************

Preorder.

92 -> 11 -> 65 -> 42 -> 29 -> 35 -> 31 -> 75 -> 73 -> 81 -> 98 -> 93 ->

*****************

Postorder.

31 -> 35 -> 29 -> 42 -> 73 -> 81 -> 75 -> 65 -> 11 -> 93 -> 98 -> 92 ->

_______________________________________________________________________________________

The desired output would be

==========================================

| BINARY TREES |

==========================================

| Create a binary tree using n random number. |

| Choose an Option |

| 1. While Loop - recursive |

| 2. For Loop - recursive |

| 3. While Loop - non-recursive |

| 4. For Loop - non-recursive |

==========================================

Select an option: 3

Option 3 selected While Loop - non-recursive

Enter the total number of random elements to create the binary tree with:

12

92 11 65 98 42 75 29 35 73 31 93 81

Inorder.

11 -> 29 -> 31 -> 35 -> 42 -> 65 -> 73 -> 75 -> 81 -> 92 -> 93 -> 98 ->

*****************

Preorder.

92 -> 11 -> 65 -> 42 -> 29 -> 35 -> 31 -> 75 -> 73 -> 81 -> 98 -> 93 ->

*****************

Postorder.

31 -> 35 -> 29 -> 42 -> 73 -> 81 -> 75 -> 65 -> 11 -> 93 -> 98 -> 92 ->

Beceriler: Java

Daha fazlasını görün: non recursive program java, binary tree traversal java, recursive tree method, number nodes tree, trees nodes, list numbers binary, binary trees java, binary trees, binary tree nodes, binary elements, ide number, binary number, recursive, print binary tree, options java, java netbeans, java console, java binary trees, binary, binary options, binary option, program linked list, gui implemented, java console gui, traverse

İşveren Hakkında:
( 6 değerlendirme ) Boca Raton, Colombia

Proje NO: #4433393

Seçilen:

Calleus

Hi, I have experience with JAVA and data structures. Let me help you. I am ready to start.

3 gün içinde 70$ USD
(12 Değerlendirme)
3.9

2 freelancer bu iş için ortalamada 77$ teklif veriyor

samitXI

Please check your inbox. Thanks

1 gün içinde 84$ USD
(64 Değerlendirme)
5.8