Skip to content

Instantly share code, notes, and snippets.

@rohith2506
Created March 2, 2015 09:44
Show Gist options
  • Save rohith2506/7bc9ec3b31b4520fb453 to your computer and use it in GitHub Desktop.
Save rohith2506/7bc9ec3b31b4520fb453 to your computer and use it in GitHub Desktop.
BST to sorted DLL
// 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