LL TO BST

From: puzzlecracker (ironsel2000_at_gmail.com)
Date: 01/19/05


Date: 19 Jan 2005 14:09:46 -0800

Do you see any problems with the following algorithm that converts Link
list to Binary Search tree. Can you think of a better solution?

node* LLtoBST(node *head, int num)
{

node *root=head;
int i, mid=(num+1)/2;

if(!head) return NULL;

if(n<=1){
head->prev=NULL;
head->next=NULL;
}

else{
for (int i=0;i<mid;++i,root=root->next)
;
root->prev=LLtoBST(head, mid-1);
root->next=LLtoBST(root->next,mid-1);
}
    return root;
           
}



Relevant Pages

  • LL TO BST
    ... Do you see any problems with the following algorithm that converts Link ... list to Binary Search tree. ... node* LLtoBST(node *head, int num) ...
    (comp.lang.cpp)
  • LL TO BST
    ... Do you see any problems with the following algorithm that converts Link ... list to Binary Search tree. ... node* LLtoBST(node *head, int num) ...
    (comp.lang.c)
  • linked lists
    ... struct node* addtotail(struct node* head, int num); ... void printlist; ...
    (comp.lang.c)