SHARE
TWEET

Untitled

a guest Jul 17th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. vector <int> a = {0};
  6.  
  7. void insert(int ele){
  8.     int temp;
  9.     a.push_back(ele);
  10.     long last = a.size()-1;
  11.     while(a[last] > a[last/2] && last > 1){
  12.         temp = a[last];
  13.         a[last] = a[last/2];
  14.         a[last/2] = temp;
  15.         last = last/2;
  16.     }
  17. }
  18.  
  19. int main(){
  20.    
  21.     insert(30);
  22.     insert(20);
  23.     insert(15);
  24.     insert(5);
  25.     insert(10);
  26.     insert(12);
  27.     insert(6);
  28.     insert(40);
  29.  
  30.     for(int i=1;i<a.size();i++){
  31.         cout << a[i] << " ";                    // Use Treevis command line tool to visualize the tree
  32.     }
  33. }
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. OK, I Understand
 
Top