knowledge-database (beta)

Current group: comp.theory.

LL TO BST

LL TO BST  
puzzlecracker
From:puzzlecracker
Subject:LL TO BST
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;inext)
;
root->prev=LLtoBST(head, mid-1);
root->next=LLtoBST(root->next,mid-1);
}
return root;

}
   

Copyright © 2006 knowledge-database   -   All rights reserved