• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Nov 16th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. struct treap {
2.       pair <int,int> val;
3.       treap *left;
4.       treap *right;
5.       treap(pair <int,int> x) : val(x), left(NULL), right(NULL) {}
6.   };
7. bool cmp (const pair <int , int> &p1 , const pair <int , int> &p2 )
8. {
9.     return p1.second > p2.second;
10. }
11.
12. treap* insert_ya_batouta (treap* root , pair <int , int> &p)
13. {
14.     if (root == nullptr)
15.     {
16.         treap* add = new treap(p);
18.     }
19.     pair <int , int> cur_pair = root -> val;
20.
21.     int cur_val = cur_pair.first;
22.     int cur_p = p.first;
23.
24.     if (cur_p < cur_val)
25.         root -> left = insert_ya_batouta(root -> left , p);
26.     else
27.         root -> right = insert_ya_batouta(root -> right , p);
28.     return root;
29. }
30.
31. void print (treap* root)
32. {
33.     if (root == nullptr)
34.         return;
35.     print (root -> left);
36.     pair <int , int> val = root -> val;
37.     cout << val.first << " "<<val.second<< endl;
38.     print (root -> right);
39.
40. }
41. int main() {
42.
43.     vector < pair < int , int> > vec = {{1, 4}, {8, 5}, {3, 6}, {10, -1}, {4, 7}};
44.
45.     sort(vec.begin(), vec.end(), cmp);
46.
47.     treap* root = new treap(vec[0]);
48.
49.     for (int i = 1 ; i < vec.size(); i++)
50.     {
51.         insert_ya_batouta (root , vec[i]);
52.     }
53.     print (root);
54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top