Level order traversel in bst


/*
struct node
{
    int data;
    node* left;
    node* right;
}*/
int max(int a,int b)
    {
    if(a>b)
        return a;
    else
        return b;
}
 int  height(struct node *root)
     {
     if(root==NULL)
         return 0;
     else
         return 1+max(height(root->left),height(root->right));
 }
void printGivenLevel(struct node* root, int level)
{
    if (root == NULL)
        return;
    if (level == 1)
        printf("%d ", root->data);
    else if (level > 1)
    {
        printGivenLevel(root->left, level-1);
        printGivenLevel(root->right, level-1);
    }
}
void LevelOrder(struct node* root)
{
    int h = height(root);
    int i;
    for (i=1; i<=h; i++)
        printGivenLevel(root, i);
}

Comments

Popular posts from this blog

How whatsapp works

ABOUT WHATSAPP

Edit Java Class file at runtime