#include <iostream>
using namespace std;
int leftchild(int nodeindex) // returns the index of the left child
{
return nodeindex *2 + 1 ;
}
int rightchild(int nodeindex) // returns the index of the right child
{
return nodeindex * 2 +2;
}
int inorder(int *mas, int nodeindex, int i, int *arr) // a recursive function to print the nodes values, put in array
{
if (mas[nodeindex] == 0) return 0 ;
inorder(mas, leftchild(nodeindex), i, arr) ;
arr[i]=mas[nodeindex];
inorder(mas, rightchild(nodeindex), i, arr);
}
int main () {
int mas[93]={2,3,1,9,8,7,6,5};
int arr[9];
inorder(mas, 0, 0, arr);
for (int k=0; k<10; k++)
cout <<"inorder " << arr[k] << endl;
system("pause");
return 0;
}
hey, all. this is my code for binary tree in array, for inorder traverse, i want put these nums in array, in inorder sequence,,,but it is not work
when i write cout, it works...there is somethink with i , i dont konow what

New Topic/Question
Reply




MultiQuote



|