Skip to content

Instantly share code, notes, and snippets.

@rohith2506
Created March 3, 2015 13:11
Show Gist options
  • Save rohith2506/7676f839cb289653b9ce to your computer and use it in GitHub Desktop.
Save rohith2506/7676f839cb289653b9ce to your computer and use it in GitHub Desktop.
Clone binary tree using random pointers
// 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