[algogeeks] Re: convert a sorted DLL to bst

2011-12-11 Thread Lucifer
1) Get the count of nodes in the given DLL. Say its, n. 2) Call convert(0, n-1, headPtrToDLL); node* convert(int start, int end, node **head) { node * root = NULL; if (start end) return NULL; int mid = (start + end) / 2; node * left = convert(

[algogeeks] Re: convert a sorted DLL to bst

2011-12-11 Thread Gene
This is nice. There is also an article on how to do this iteratively with a stack: http://groups.google.com/group/comp.programming/msg/41f46b2801c4f84e This solution actually traverses a BST of any shape, tears it apart, and reassembles it as a perfectly balanced tree. However, it will also