node *root;

node * build(int height)
{
node *r, *temp;
for(i=1, r=null; i<=height && root; i++)
{
temp = root;
root=root->left;
temp->right=r;
r=temp;
r->left = build(i-1);
}
return r;
}

void main()
{
node *tree;
//root contains original tree
tree = buld(n); // n=height of of new tree
}


i will explain with an example

ake an example 6-5-4-3-2-1
here N=6, height of the new tree = 3
so main will call build(3)

it will build the tree as follows
in build(3)
i=1      6    root 5-4-3-2-1

i=2         5   root 4-3-2-1
           /   \
 build(1)     6
   in build(1)
   i=1        4    root 3-2-1
so    5
      /   \
     4     6
i=3     3       root 2-1
      /     \
build(2)   5
            /   \
          4     6

    in build(2)
    i=1     2     root 1
    i =2    1     root null
            /   \
    build(1)   2
        in build(1)
        i=1 as root null it will be null
    so      1
               \
                 2
so     3
      /     \
    1       5
      \     /   \
      2   4     6

this way it will work..
by the way can you give me an example that does not work ? it will be
great help as i can find the bug in my program. i am waiting for your
reply. for ne clarification i am here, you can ask me :)

On 3/17/06, pramod <[EMAIL PROTECTED]> wrote:
>
> Malay, I think your solution gives wrong results. Can you please verify
> and explain us.
>
>
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to