Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. struct Element {
  8.     int value = 0;
  9.     int level = 0;
  10.  
  11.     bool IsRed = false;
  12.  
  13.     Element* nextl = NULL;
  14.     Element* nextr = NULL;
  15.     Element* previous = NULL;
  16. };
  17.  
  18. void Walk(Element *&Way, int value) {
  19.     int Level = 0;
  20.     Element* Current = Way;
  21.     do {
  22.         if ((Current->nextr == NULL && Current->value < value) || (Current->nextl == NULL && Current->value > value))
  23.             break;
  24.  
  25.         if (Current->value < value)
  26.             Current = Current->nextr;
  27.         else
  28.         if (Current->value > value)
  29.             Current = Current->nextl;
  30.     } while (true);
  31.     Way = Current;
  32. }
  33.  
  34. void SetElement(int value, Element* root) {
  35.     Element* newElement = new Element;
  36.     newElement->value = value;
  37.     Element* tail = root;
  38.  
  39.     Walk(tail, value);
  40.  
  41.     if (tail->value < value) {
  42.         tail->nextr = newElement;
  43.         newElement->previous = tail;
  44.         newElement->level = newElement->previous->level + 1;
  45.     }
  46.     if (tail->value > value) {
  47.         tail->nextl = newElement;
  48.         newElement->previous = tail;
  49.         newElement->level = newElement->previous->level + 1;
  50.     }
  51. }
  52.  
  53. void TreeOut(Element* root, int Count) {
  54.     Element **List = new Element*[Count];
  55.     int Pos = 0;
  56.     do {
  57.         Pos = pow(2, root->level) - 1;
  58.         List[Pos] = root;
  59.  
  60.         if()
  61.  
  62.     }
  63.  
  64.  
  65. }
  66.  
  67. int main()
  68. {
  69.  
  70.     int value = 0;
  71.     int Count = 0;
  72.  
  73.     Element* root = new Element;
  74.  
  75.     cin >> value;
  76.     cout << endl;
  77.  
  78.     root->value = value;
  79.  
  80.  
  81.  
  82.     do {
  83.         cin >> value;
  84.         if (value == 95)
  85.             break;
  86.         SetElement(value, root);
  87.         ++Count;
  88.     } while (true);
  89.  
  90.     TreeOut(root, Count);
  91.  
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement