Created
March 3, 2015 13:11
-
-
Save rohith2506/7676f839cb289653b9ce to your computer and use it in GitHub Desktop.
Clone binary tree using random pointers
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
// Use Hashing | |
// map<node*, node* > = new map<node* , node* > | |
// Author: Rohith | |
// This is little bit tricky. Why?? i can't simply create all nodes and recrusively call them. | |
// we can do like this | |
void copylandr(t){ | |
node *clone = new node(t->key); | |
mp[t] = clone; | |
copylandr(t->left, mp); | |
copylandr(t->right,mp); | |
} | |
void copyrandom(t, clone){ | |
clone->random = mp[t->random]; | |
copyrandom(t->left, clone); | |
copyrandom(t->right,clone); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment