|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|||
|
Creating binary tree from an array
I have to create a binary tree from an array of elements level wise..i.e a[0] is root.a[1] and a[2] are a[0]'s children.a[4],a[5] are a[2] children and so on.
Can someone tell me how to do this recursively or non-recursively? Thanks |
|
|||
|
Quote:
It's in C++ and i searched a lot in Google. It's NOT the binary search tree that we have to implement in which the root value is taken and elements smaller than the root are placed at the left and larger elements are placed on the right. It's actually a threaded binary tree that we have to implement. Here we are not concerned about the actual values of the elements.All we have to do is take an array of values as user input and create a binary tree as I told above. array[0] -- root array[1] -- root's left child array[2] -- root's right child array[3] -- array[1] 's left child array[4] -- array[1]'s right child and so on... the tree would look like this -----------------a[0]------------- ----------a[1]----------a[2]------ -------a[3]----a[4]---a[5]---a[6]--- ----a[7]--a[8] ....................... and so on.(hope the above looks like a tree,I tried my best to show it!!) ![]() So, it's basically filling up the tree level wise from the elements in the given array(irrespective of the actual values of the elements) Last edited by Code_Programs : April 20th, 2008 at 11:16 PM. Reason: diagram isnt represented correctly |
|
|||
|
To Madhyena,
Thanks for the link, but the way i have to create my binary tree -- that's no where mentioned in the link you sent me. I am very willing to learn myself given the right resource.Let me know if you find something related to my description which I posted earlier. Thanks!! |
|
||||
|
the first google link should answer your question.
|
|
|||
|
The link which I followed -- It shows how to count the nodes. I am not sure how my problem is cleared.
|