binary tree | Sololearn: Learn to code for FREE!

binary tree

Hello I have a question that how can I implement binary tree on an array which I know size of it, I mean that the function prototype is : struct* binarytree(int Arr[],int sizeArr); what is the code?

15th Dec 2018, 6:11 AM
Matin Zamani
Matin Zamani - avatar
3 Antworten
+ 3
Hello, ­čśŐ --> what is the code!? Please, Use the search feature before posting as to reduce the number of duplicate threads in Q/A section!­čĹŹ
15th Dec 2018, 6:27 AM
Danijel Ivanovi─ç
Danijel Ivanovi─ç - avatar
You can use this method : The sons of each node (placed at index i in the array) is of index 2*i for the left son and 2*i + 1 for the right son All you have left is to find a way to know when you reach a leave (do array of pointers ? A specific value forbidden elsewhere ?)
15th Dec 2018, 3:56 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
27th Aug 2021, 8:40 PM
Adnan Mahmud
Adnan Mahmud - avatar