LL TO BST
From: puzzlecracker (ironsel2000_at_gmail.com)
Date: 01/19/05
- Next message: poopdeville_at_gmail.com: "Re: THIS STATEMENT HAS NO PROOF IN ANY SYSTEM = true or false?"
- Previous message: Termite of Tempation: "Re: How many flips of DIAG are on the infintie list of infinite con flippers?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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;
}
- Next message: poopdeville_at_gmail.com: "Re: THIS STATEMENT HAS NO PROOF IN ANY SYSTEM = true or false?"
- Previous message: Termite of Tempation: "Re: How many flips of DIAG are on the infintie list of infinite con flippers?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|