i was asked to create a binary tree,populate it with the elements of a given array,sort it and output the items in the tree using post order,i can handle the rest except the populating of the tree with the elements of a given array since i was asked to insert the arrays' elements into the binary tree with respect to the way they appear in the array without following the normal rule of item insertion in a binary tree i.e assuming there exist an array(int[]a) such that 2,5,36,7,78,4 are members of the array(ordered form) then i should also make sure that the nodes of the binary tree are of the same order...e.g A[0] = 2,A[1] = 5,A[2] = 36...A[5] = 4 then for the binary tree root = 2,root.left = 5,root.right = 36,root.left.left =7,root.right.right=78 e.t.c , i need a help or better still a sample code on how to write this stuff.........
sam.udo
0
Newbie Poster
Recommended Answers
Jump to PostThis code snippet should help
public class BinaryTreeTest { public static void main(String[] args) { new BinaryTreeTest().run(); } static class Node { Node left; Node right; int value; public Node(int value) { this.value = value; } } public void run() { // build the simple tree from …
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.