Advertisement
radmickey

Untitled

Dec 7th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct Node {
  5.     int value;
  6.     int cur;
  7.     int left;
  8.     int right;
  9.     int height;
  10.     Node() {
  11.         height = 0;
  12.         right = 0;
  13.         left = 0;
  14.         cur = 0;
  15.         value = 0;
  16.     }
  17.  
  18.     Node(int v, int l, int r, int c) {
  19.         value = v;
  20.         left = l;
  21.         right = r;
  22.         cur = c;
  23.     }
  24. };
  25.  
  26. int Height_dp(int i, std::vector<Node>& AVL) {
  27.     if (i == 0) {
  28.         return 0;
  29.     }
  30.  
  31.     if (AVL[i].height != 0) {
  32.         return AVL[i].height;
  33.     }
  34.  
  35.     AVL[i].height = std::max(Height_dp(AVL[i].right, AVL), Height_dp(AVL[i].left, AVL)) + 1;
  36.  
  37.     return AVL[i].height;
  38.  
  39. }
  40.  
  41. int bFactor(int i, std::vector<Node>& AVL) {
  42.     return AVL[AVL[i].right].height - AVL[AVL[i].left].height;
  43. }
  44.  
  45. void leftRotate ()
  46.  
  47. int main() {
  48.     int n;
  49.     std::cin >> n;
  50.  
  51.     std::vector<Node> avl;
  52.     avl.push_back(Node());
  53.  
  54.     int v, l, r;
  55.     for (int i = 1; i <= n; i++) {
  56.         std::cin >> v >> l >> r;
  57.  
  58.         avl.push_back(Node(v, l, r, i));
  59.     }
  60.     Height_dp(1, avl);
  61.  
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement