Re: [algogeeks] BST to Double Linked List Without Using Extra Space
On Thu, Nov 25, 2010 at 11:05 PM, mo...@ismu wrote: > > node *bst_to_dl(root) > { > node *head1=NULL,head2=NULL,*temp=NULL; > temp=(node *)calloc(1,sizeof(node)); > temp->value=root->value; > if(root-left) > head1=bst_to_dl(root-left); > if (root->right) > head2=bst_to_dl(root->right); > if(head2&&head1)//root having two children > { > head1->next=head2; > head2->prev=head1; > temp->next=head1; > head1->prev=temp; > } > else if(head1) //root having only one child >{ > temp->next=head1; > head1->prev=temp; >} > else if(head2) { temp->next=head2; head2->prev=temp; } > return temp; > } > > -- 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.
Re: [algogeeks] BST to Double Linked List Without Using Extra Space
node *bst_to_dl(root) { node *head1=NULL,head2=NULL,*temp=NULL; temp=(node *)calloc(1,sizeof(node)); temp->value=root->value; if(bst-left) head1=bst_to_dl(root-left); if (bst->right) head2=bst_to_dl(root->right); if(head2&&head1)//root having two children { head1->next=head2; head2->prev=head1; temp->next=head1; head1->prev=temp; } else if(head1) //root having only one child { temp->next=head1; head1->prev=temp; } return temp; } -- 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.
Re: [algogeeks] BST to Double Linked List Without Using Extra Space
If BST is stored in an array, which is already in level order, then there is nothing much remaining to do. On Wed, Nov 24, 2010 at 9:05 PM, vamsee marpu wrote: > Hi, > > > Can anybody help me in solving the following problem: > > > Convert a binary search tree in to a doubly linked list in level order > without using extra space : > > > BST >1 > / \ > 2 3 > / \ / \ > 4 5 6 7 > > in to double linked list as: 1==2==3==4==5==6==7 > > > I can do it using level order traversal using a queue, but the problem says > no extra space should be used, I tried a lot but can't able to figure out. > > > > Thanks, > M. Vamsee > > > -- > 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. > -- 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.