## cây nhị phân Treap

mong nọi người giúp đỡ! mình tạo cây treap nhưng không hiểu sao chỉ tạo được 1 node

#include <iostream>
#include <queue> // Use Queue is available in C ++

using namespace std;

// create one node of the tree

class Node {
int key;
int priority;
Node* left;
Node* right;
public:
Node() { key = -1; priority = -1; left = NULL; right = NULL; };
void setKey(int Key) { key = Key; };
void setPriority(int Priority) { priority = Priority; }
void setLeft(Node* Left) { left = Left; };
void setRight(Node* Right) { right = Right; };
int Key() { return key; };
int Priority() { return priority; };
Node* Left() { return left; };
Node* Right() { return right; };
};

// create binary tree

class Tree {
public:
Tree();
~Tree();
Node* root;
Node* Root() { return root; };
void Insert(int key, int priority);
void levelOrder(Node* n);
private:
void addNode(int key, int priority, Node* leaf);
void freeNode(Node* leaf);
void split(Node* node, int key, Node* leftTree, Node* rightTree);
Node* merge(Node* leftTree, Node* rightTree);
};

Tree::Tree() {
root = NULL;
}

Tree::~Tree() {
freeNode(root);
}

void Tree::freeNode(Node* leaf)
{
if (leaf != NULL)
{
freeNode(leaf->Left());
freeNode(leaf->Right());
delete leaf;
}
}

void Tree::addNode(int key, int priority) {
if (root == NULL) {
Node* n = new Node();
n->setKey(key);
n->setPriority(priority);
root = n;
}
else {
}
}

void Tree::addNode(int key, int priority, Node* leaf)
{
if (key <= leaf->Key()) {
if (leaf->Left() != NULL)
else
{
Node* n = new Node();
n->setKey(key);
n->setPriority(priority);
leaf->setLeft(n);
}
}
else {
if (leaf->Right() != NULL)
else {
Node* n = new Node();
n->setKey(key);
n->setPriority(priority);
leaf->setRight(n);
}
}
}

void Tree::split(Node* node, int key, Node* leftTree, Node* rightTree)
{
if (node == NULL) {
leftTree = NULL;
rightTree = NULL;
return;
}

if (node->Key() <= key) {
split(node->Right(), key, node->Right(), rightTree);
leftTree = node;
}
else {
split(node->Left(), key, leftTree, node->Left());
rightTree = node;
}
}

Node* Tree::merge(Node* leftTree, Node* rightTree)
{
if (leftTree == NULL) {
return rightTree;
}
if (rightTree == NULL) {
return leftTree;
}

if (rightTree->Priority() > leftTree->Priority()) {
Node* q = merge(leftTree, rightTree->Left());
rightTree->setLeft(q);
return rightTree;
}
else {
Node* q = merge(leftTree->Right(), rightTree);
leftTree->setRight(q);
return leftTree;
}
}

void Tree::Insert(int key, int priority)
{
if (root == NULL) {
root = new Node();
root->setKey(key);
root->setPriority(priority);
return;
}

Node* leftTree = root->Left();
Node* rightTree = root->Right();
split(root, key, leftTree, rightTree);
Node* q = new Node();
q->setKey(key);
q->setPriority(priority);
root = merge(leftTree, q);
root = merge(root, rightTree);

}

// Traversing the tree in width

void Tree::levelOrder(Node* n) {

queue<Node*> q;

q.push(n);

while (!q.empty())
{
Node* p = q.front(); // take the surrender value
cout << p->Key() << " " << p->Priority() << endl; // print key and priority
if (p->Left() != NULL)
q.push(p->Left());

if (p->Right() != NULL)
q.push(p->Right());

q.pop();
}
}

int main()
{
Tree* tree = new Tree();

// create binary tree

int N;
cin >> N;
int Xi, Yi;

for (int i = 0; i < N; i++)
{
cin >> Xi >> Yi;
tree->Insert(Xi, Yi);
}

// print

tree->levelOrder(tree->Root());

system("pause");

return 0;
}