Created
March 2, 2015 09:44
-
-
Save rohith2506/7bc9ec3b31b4520fb453 to your computer and use it in GitHub Desktop.
BST to sorted DLL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Converting bst to sorted DLL | |
// go in in order and and keep track of previous node and make it previous to current node and current node next to this node. | |
void bsttodll(node *root, node **head){ | |
if(root == NULL) return ; | |
static node *prev = NULL; | |
bsttodll(root->left, head); | |
if(prev == NULL) *head = root; | |
else { | |
root -> previous = prev; | |
prev -> next = previous; | |
} | |
bsttodll(root->right, head); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment