Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Treaps - Insertion
// base case
if (root == nullptr)
root = new TreapNode(data);
// if given data is less than the root node, insert in the left subtree
// else insert in the right subtree
if (data < root->data)
insertNode(root->left, data);
// rotate right if heap property is violated
if (root->left != nullptr && root->left->priority > root->priority)
insertNode(root->right, data);
// rotate left if heap property is violated
if (root->right != nullptr && root->right->priority > root->priority)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.