make a function which returns the missle of the LL middle(node *) now, node * listtotree(node *head){ if( !head || !head->next){ return head; node *temp= middle(head); node *p=head; while(p->next!=temp){ p=p->next; } p->next=NULL; node *q=temp->next; temp->next=NULL; temp->prev=listtotree(head); temp->next=listtotree(q); return temp; }
i think this will do :) On Sun, Aug 1, 2010 at 10:57 AM, Shiv ... <shivsinha2...@gmail.com> wrote: > No it won't it will just reduce the height of tree to n/2 (from n). > > My algo- > 1. Parse in triplets. For every 3 nodes make the second one parent of other > two. Also, queue up such parents. > 2. repeat step 1 till you have only 1 node left (root). > > But this may give a tree 'imbalanced at root. we may need to do some height > re-balancing. > > -Thanks > > > > On Sun, Aug 1, 2010 at 9:26 AM, Manjunath Manohar < > manjunath.n...@gmail.com> wrote: > >> find the middle of the list and make it as the root..thus i this maner u >> will get a balanced tree.. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.