Non-recursive Binary Tree Traversal Program in Java
$30-250 USD
进行中
已发布大约 11 年前
$30-250 USD
货到付款
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 ->