Print array having level order in inorder

PROBLEM :
given array represents the level order traversal of BST , print it in sorted manner (inorder traversal)

Given an array that stores a complete Binary Search Tree, write a function that efficiently prints the given array in ascending order.

For example, given an array [4, 2, 5, 1, 3], the function should print 1, 2, 3, 4, 5



--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

void array_level_order(int a[],int start,int end)
{
if(start>end)
return ;
array_level_order(a,start*2+1,end) ;
cout<<a[start]<<" " ;
array_level_order(a,start*2+2,end) ;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )