C Write a function bool isLevelint a int n which determines

C++

Write a function bool isLevel(int *a, int n) which determines if the array a is a valid level-order listing of a BBST.

Solution

If the level order is represented in the array with an index i, a node i\'s left child is 2i, right child is 2i+1 and parent of i is i/2.

bool isLevel(int *a, int n){

int j=1; // flag variable

for (i=1;i<n;i++) { // from 1st index to last (size of array with n)

if (leftchild(a[i])==a[2i] && rightchild(a[i]==a[2i+1] && parent(a[i])==i/2)

j++;

}

if (j==n)

return true;

else

return false;

}

C++ Write a function bool isLevel(int *a, int n) which determines if the array a is a valid level-order listing of a BBST.SolutionIf the level order is represen

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site