GerONSo

Untitled

Nov 4th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. pair<treap*, treap*> split(treap *&root, int key) {
  2. if(root == nullptr) {
  3. return {nullptr, nullptr};
  4. }
  5. int root_key = get_size(root->left);
  6. if(key > root_key) {
  7. pair<treap*, treap*> splitted = split(root->right, key);
  8. root->right = splitted.x;
  9. update(root);
  10. return {root, splitted.y};
  11. }
  12. else {
  13. pair<treap*, treap*> splitted = split(root->left, key);
  14. root->left = splitted.y;
  15. update(root);
  16. return {splitted.x, root};
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment