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) ;
}
---------------------------------------------------------------------------------
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
Post a Comment