Advertisement
Margoshinka

govno3

Apr 9th, 2022
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.74 KB | None | 0 0
  1. using namespace std;
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <conio.h>
  5. class GameObject
  6. {
  7. protected:
  8.     bool printed;
  9. public:
  10.  
  11.     virtual int GetUniqueIdentifier() = 0;
  12.  
  13.  
  14.     virtual void UniqueIdentifier(int u) = 0;
  15.       void Print() {
  16.           printed = true;
  17.         cout <<"Уникальный идентификатор " << GetUniqueIdentifier() << endl;
  18.        
  19.     };
  20. };
  21. struct RBTree { RBTree* Left, * Right, * Parent; int Data; bool red; GameObject* obj; };
  22. void ClassDefinition(GameObject* obj);
  23. //создание красно-черного дерева
  24. /*void Make_RBTree(RBTree** Node, int n) {
  25.     GameObject* Data;
  26.     while (n > 0) {
  27.         cout << "Введите значение ";
  28.         cin >> Data;
  29.         Insert_Node(Node, Data);
  30.         n--;
  31.     }
  32. }*/
  33. RBTree* NIL = new RBTree();
  34.  
  35. void Insert_Fixup(RBTree** Node, RBTree* New_Node);
  36. void Rotate_Left(RBTree** Node, RBTree* Current);
  37. void Rotate_Right(RBTree** Node, RBTree* Current);
  38. //добавление узла в красно-черное дерево
  39. void Insert_Node(RBTree** Node, GameObject* Data) {
  40.     RBTree** Curent, * Parent, * New_Node;
  41.     Curent = Node;
  42.     Parent = NIL; //узел, под который мы будем вставлять
  43.     // Поиск местоположения
  44.     while (*Curent != NIL) {
  45.         Parent = (*Curent);
  46.         Curent = Data->GetUniqueIdentifier() < (*Curent)->Data ? &((*Curent)->Left) : &((*Curent)->Right);
  47.     }
  48.     // Создание нового узла
  49.     New_Node = new RBTree();
  50.     New_Node->Data = Data->GetUniqueIdentifier();
  51.     New_Node->obj = Data;
  52.     New_Node->Parent = Parent;
  53.     New_Node->Left = NIL;
  54.     New_Node->Right = NIL;
  55.     New_Node->red = true;
  56.     // Вставка элемента в дерево
  57.     if (Parent != NIL) {
  58.         if (Data->GetUniqueIdentifier() < Parent->Data) Parent->Left = New_Node;
  59.         else Parent->Right = New_Node;
  60.     }
  61.     else (*Curent) = New_Node;
  62.     Insert_Fixup(Node, New_Node);
  63. }
  64.  
  65. // Поддержка баланса дерева после вставки нового элемента
  66. void Insert_Fixup(RBTree** Node, RBTree* New_Node) {
  67.     RBTree* Current = New_Node;
  68.     // Проверка свойств дерева
  69.     while (Current != *(Node) && Current->Parent->red == true) {
  70.         // если есть нарушение
  71.         if (Current->Parent == Current->Parent->Parent->Left) {
  72.             RBTree* ptr = Current->Parent->Parent->Right;
  73.             if (ptr->red == true) {
  74.                 Current->Parent->red = false;
  75.                
  76.                 ptr->red = false;
  77.                 Current->Parent->Parent->red = true;
  78.                 Current = Current->Parent->Parent;
  79.             }
  80.             else {
  81.                 if (Current == Current->Parent->Right) {
  82.                     // сделать Current левым потомком
  83.                     Current = Current->Parent;
  84.                     Rotate_Left(Node, Current);
  85.                 }
  86.                 // перекрасить и повернуть
  87.                 Current->Parent->red = false;
  88.                 Current->Parent->Parent->red = true;
  89.                 Rotate_Right(Node, Current->Parent->Parent);
  90.             }
  91.         }
  92.         else {
  93.             RBTree* ptr = Current->Parent->Parent->Left;
  94.            
  95.                 if (ptr->red == true ) {
  96.                     Current->Parent->red = false;
  97.  
  98.                     ptr->red = false;
  99.                     Current->Parent->Parent->red = true;
  100.                     Current = Current->Parent->Parent;
  101.                 }
  102.            
  103.             else {
  104.                 if (Current == Current->Parent->Left) {
  105.                     Current = Current->Parent;
  106.                     Rotate_Right(Node, Current);
  107.                 }
  108.                 Current->Parent->red = false;
  109.                 Current->Parent->Parent->red = true;
  110.                 Rotate_Left(Node, Current->Parent->Parent);
  111.             }
  112.         }
  113.     }
  114.     (*Node)->red = false;
  115. }
  116.  
  117. //поворот узла Current влево
  118. void Rotate_Left(RBTree** Node, RBTree* Current) {
  119.     RBTree* ptr = Current->Right;
  120.     Current->Right = ptr->Left;
  121.     if (ptr->Left != NIL) ptr->Left->Parent = Current;
  122.     if (ptr != NIL) ptr->Parent = Current->Parent;
  123.     if (Current->Parent != NIL) {
  124.         if (Current == Current->Parent->Left)
  125.             Current->Parent->Left = ptr;
  126.         else
  127.             Current->Parent->Right = ptr;
  128.     }
  129.     else {
  130.         (*Node) = ptr;
  131.     }
  132.     ptr->Left = Current;
  133.     if (Current != NIL) Current->Parent = ptr;
  134. }
  135.  
  136. //поворот узла Current вправо
  137. void Rotate_Right(RBTree** Node, RBTree* Current) {
  138.     RBTree* ptr = Current->Left;
  139.     Current->Left = ptr->Right;
  140.     if (ptr->Right != NIL) ptr->Right->Parent = Current;
  141.     if (ptr != NIL) ptr->Parent = Current->Parent;
  142.     if (Current->Parent != NIL) {
  143.         if (Current == Current->Parent->Right)
  144.             Current->Parent->Right = ptr;
  145.         else
  146.             Current->Parent->Left = ptr;
  147.     }
  148.     else {
  149.         (*Node) = ptr;
  150.     }
  151.     ptr->Right = Current;
  152.     if (Current != NIL) Current->Parent = ptr;
  153. }
  154.  
  155.  
  156.  
  157.  
  158. //прямой обход красно-черного дерева
  159. void PreOrder_RBTree(RBTree* Node) {
  160.     if (Node != NIL) {
  161.         ClassDefinition(Node->obj);
  162.         PreOrder_RBTree(Node->Left);
  163.         PreOrder_RBTree(Node->Right);
  164.     }
  165. }
  166.  
  167. //обратный обход красно-черного дерева
  168. void PostOrder_RBTree(RBTree* Node) {
  169.     if (Node != NIL) {
  170.         PostOrder_RBTree(Node->Left);
  171.         PostOrder_RBTree(Node->Right);
  172.         cout << Node->Data << " ";
  173.     }
  174. }
  175.  
  176. //симметричный обход красно-черного дерева
  177. void SymmetricOrder_RBTree(RBTree* Node) {
  178.     if (Node != NIL) {
  179.         PostOrder_RBTree(Node->Left);
  180.       cout <<  Node->Data << " ";
  181.         PostOrder_RBTree(Node->Right);
  182.     }
  183. }
  184.  
  185. //проверка пустоты красно-черного дерева
  186. bool Empty_RBTree(RBTree* Node) {
  187.     return (Node == NIL ? true : false);
  188. }
  189.  
  190. //освобождение памяти, выделенной под красно-черное дерево
  191. void Delete_RBTree(RBTree* Node) {
  192.     if (Node != NIL) {
  193.         Delete_RBTree(Node->Left);
  194.         Delete_RBTree(Node->Right);
  195.         delete(Node);
  196.     }
  197. }
  198. RBTree* FindItem(int  data, RBTree* Tree)
  199. {
  200.     RBTree* ret = Tree;
  201.     while (ret!=NIL)
  202.     {
  203.         if (data < ret->Data)
  204.         {
  205.             ret = ret->Left;
  206.         }
  207.         else if (data > ret->Data)
  208.         {
  209.             ret = ret->Right;
  210.         }
  211.         else
  212.         {
  213.             break;
  214.         }
  215.     }
  216.     return ret;
  217. }
  218. void PrintTree1(RBTree* Tree)
  219. {
  220.     if (Tree != NIL)
  221.     {
  222.         cout << Tree->Data;
  223.         cout << "-" << Tree->red;
  224.         cout << " (";
  225.         PrintTree1(Tree->Left);
  226.         cout << ") ";
  227.         cout << " (";
  228.         PrintTree1(Tree->Right);
  229.         cout << ") ";
  230.     }
  231.     else cout << "null";
  232. }
  233.  
  234.  
  235. class PhysicalObject : public virtual GameObject
  236. {
  237.  
  238. public:
  239.     virtual int GetWeight() = 0;
  240.     virtual void Weight(int w) = 0;
  241.     virtual void  Print() {
  242.         if (!printed){
  243.            
  244.             cout << "Вес " << GetWeight() << endl;
  245.             GameObject::Print();
  246.         }
  247.            
  248.         else
  249.            
  250.         cout << "Вес " << GetWeight() << endl;
  251.        
  252.     }
  253. };
  254. class GraphicObject : public virtual GameObject
  255. {
  256. public:
  257.     virtual string GetTexture() = 0;
  258.     virtual void Texture(string t) = 0;
  259.     virtual void Print(){
  260.         if (!printed) {
  261.            
  262.             cout << "Текстура " << GetTexture() << endl;
  263.             GameObject::Print();
  264.            
  265.         }
  266.  
  267.         else
  268.  
  269.            
  270.         cout << "Текстура " << GetTexture() << endl;
  271.        
  272.     }
  273. };
  274. class Projectile : public virtual PhysicalObject
  275. {
  276. private:
  277.     int weight;
  278.     string caliber;
  279.     int uniqueIdentifier;
  280. public:
  281.    
  282.     void Caliber(string c) {
  283.         caliber = c;
  284.     }
  285.     void Weight(int w) override {
  286.         weight = w;
  287.     }
  288.     void UniqueIdentifier(int u) override {
  289.         uniqueIdentifier = u;
  290.        
  291.     }
  292.     int GetUniqueIdentifier() override {
  293.         return uniqueIdentifier;
  294.     }
  295.     int GetWeight() override {
  296.         return weight;
  297.     }
  298.     string GetCaliber() {
  299.         return caliber;
  300.     }
  301.     void  Print()    {
  302.        
  303.         cout << "Снаряд" << endl;
  304.         cout << "Калибр: " << GetCaliber() << endl;
  305.        
  306.         PhysicalObject::Print();
  307.        
  308.     }
  309.  
  310. };
  311. class TransportVehicle : public virtual PhysicalObject
  312. {
  313. private:
  314.     int weight;
  315.     int uniqueIdentifier;
  316.     int enginePower;
  317. public:
  318.    
  319.     void EnginePower(int e) {
  320.         enginePower = e;
  321.     }
  322.     void Weight(int w) override {
  323.         weight = w;
  324.     }
  325.     void UniqueIdentifier(int u) override {
  326.         uniqueIdentifier = u;
  327.        
  328.     }
  329.     int GetUniqueIdentifier() override{
  330.         return uniqueIdentifier;
  331.     }
  332.     int GetWeight() override {
  333.         return weight;
  334.     }
  335.     int GetEnginePower() {
  336.         return enginePower;
  337.     }
  338.     void Print()  {
  339.        
  340.         cout << "Транспортное средство" << endl;
  341.         cout << "Мощность двигателя: " << GetEnginePower() << endl;
  342.  
  343.         PhysicalObject::Print();
  344.        
  345.     }
  346. };
  347. class Tank : public virtual TransportVehicle, public virtual GraphicObject
  348. {
  349. private:
  350.     string texture;
  351.     int uniqueIdentifier;
  352.     int armorThickness;
  353. public:
  354.    
  355.     void ArmorThickness(int a) {
  356.         armorThickness = a;
  357.     }
  358.     void UniqueIdentifier(int u) override {
  359.         uniqueIdentifier = u;
  360.        
  361.     }
  362.     void Texture(string t) override {
  363.         texture = t;
  364.     }
  365.     int GetUniqueIdentifier() override {
  366.         return uniqueIdentifier;
  367.     }
  368.     string GetTexture() override {
  369.         return texture;
  370.     }
  371.     int GetArmorThickness() {
  372.         return armorThickness;
  373.     }
  374.     void Print()  {
  375.         printed = false;
  376.         cout << "Танк" << endl;
  377.         cout << "Толщина брони " << GetArmorThickness() << endl;
  378.         TransportVehicle::Print();
  379.         GraphicObject::Print();
  380.        
  381.     }
  382.  
  383. };
  384. class Airplane : public virtual TransportVehicle, public virtual GraphicObject
  385. {
  386. private:
  387.     string texture;
  388.     int uniqueIdentifier;
  389.     int loadCapacity;
  390. public:
  391.    
  392.     void LoadCapacity(int l) {
  393.         loadCapacity = l;
  394.     }
  395.     void UniqueIdentifier(int u) override {
  396.         uniqueIdentifier = u;
  397.      
  398.     }
  399.     string GetTexture() override {
  400.         return texture;
  401.     }
  402.     int GetLoadCapacity() {
  403.         return loadCapacity;
  404.     }
  405.     void Texture(string t) override {
  406.         texture = t;
  407.     }
  408.     int GetUniqueIdentifier() override {
  409.         return uniqueIdentifier;
  410.     }
  411.     void Print()  {
  412.         printed = false;
  413.         cout << "Самолёт" << endl;
  414.         cout << "Грузоподъёмность " << GetLoadCapacity() << endl;
  415.         TransportVehicle::Print();
  416.         GraphicObject::Print();
  417.        
  418.     }
  419. };
  420. void ClassDefinition(GameObject* obj) {
  421.     string name = typeid(*obj).name();
  422.     if (name == "class Projectile") {
  423.         Projectile* p = dynamic_cast<Projectile*> (obj);
  424.         p->Print();
  425.     }
  426.     else if (name == "class TransportVehicle") {
  427.         TransportVehicle* t = dynamic_cast<TransportVehicle*> (obj);
  428.         t->Print();
  429.     }
  430.     else if (name == "class Tank") {
  431.         Tank* tn = dynamic_cast<Tank*> (obj);
  432.         tn->Print();
  433.     }
  434.     else if (name == "class Airplane") {
  435.         Airplane* a = dynamic_cast<Airplane*> (obj);
  436.         a->Print();
  437.     }
  438. }
  439. void DeleteFixup(RBTree* x, RBTree* root, RBTree** Tree) {
  440.  
  441.    
  442.  
  443.     while (x != root && x->red == false) {
  444.         if (x == x->Parent->Left) {
  445.             RBTree* w = x->Parent->Right;
  446.             if (w->red == true) {
  447.                 w->red = false;
  448.                 x->Parent->red =true;
  449.                 Rotate_Left(Tree, x->Parent);
  450.                 w = x->Parent->Right;
  451.             }
  452.             if (w->Left->red == false && w->Right->red ==false) {
  453.                 w->red = true;
  454.                 x = x->Parent;
  455.             }
  456.             else {
  457.                 if (w->Right->red == false) {
  458.                     w->Left->red = false;
  459.                     w->red = true;
  460.                     Rotate_Right(Tree,w);
  461.                     w = x->Parent->Right;
  462.                 }
  463.                 w->red = x->Parent->red;
  464.                 x->Parent->red = false;
  465.                 w->Right->red = false;
  466.                 Rotate_Left(Tree, x->Parent);
  467.                 x = root;
  468.             }
  469.         }
  470.         else {
  471.             RBTree* w = x->Parent->Left;
  472.             if (w->red == true) {
  473.                 w->red = false;
  474.                 x->Parent->red = true;
  475.                 Rotate_Right(Tree, x->Parent);
  476.                 w = x->Parent->Left;
  477.             }
  478.             if (w->Right->red == false && w->Left->red == false) {
  479.                 w->red = true;
  480.                 x = x->Parent;
  481.             }
  482.             else {
  483.                 if (w->Left->red == false) {
  484.                     w->Right->red = false;
  485.                     w->red = true;
  486.                     Rotate_Left(Tree,w);
  487.                     w = x->Parent->Left;
  488.                 }
  489.                 w->red = x->Parent->red;
  490.                 x->Parent->red = false;
  491.                 w->Left->red = false;
  492.                 Rotate_Right(Tree, x->Parent);
  493.                 x = root;
  494.             }
  495.         }
  496.     }
  497.     x->red = false;
  498. }
  499. RBTree* Successor(RBTree* p)
  500. {
  501.     RBTree* y = NIL;
  502.     if (p->Left != NIL)
  503.     {
  504.         y = p->Left;
  505.         while (y->Right != NIL)
  506.             y = y->Right;
  507.     }
  508.     else
  509.     {
  510.         y = p->Right;
  511.         while (y->Left != NIL)
  512.             y = y->Left;
  513.     }
  514.     return y;
  515. }
  516. void Delfix(RBTree* p, RBTree** Tree);
  517.     void DeleteNode(int Data, RBTree** Tree)
  518.     {
  519.         if (*Tree == NIL)
  520.         {
  521.             cout << "Дерево пустое" << endl;
  522.             return;
  523.         }
  524.        
  525.         RBTree* p;
  526.         p = *Tree;
  527.         RBTree* y = NIL;
  528.         RBTree* q = NIL;
  529.         int found = 0;
  530.         while (p != NIL && found == 0)
  531.         {
  532.             if (p->Data == Data)
  533.                 found = 1;
  534.             if (found == 0)
  535.             {
  536.                 if (p->Data < Data)
  537.                     p = p->Right;
  538.                 else
  539.                     p = p->Left;
  540.             }
  541.         }
  542.         if (found == 0)
  543.         {
  544.             cout << "Элемент с данным идентификатором не найден" << endl;;
  545.             return;
  546.         }
  547.         else
  548.         {
  549.            
  550.  
  551.            
  552.             if (p->Left == NIL || p->Right == NIL)
  553.                 y = p;
  554.             else
  555.                 y = Successor(p);
  556.             if (y->Left != NIL)
  557.                 q = y->Left;
  558.             else
  559.             {
  560.                 if (y->Right != NIL)
  561.                     q = y->Right;
  562.                 else
  563.                     q = NIL;
  564.             }
  565.             if (q != NIL)
  566.                 q->Parent = y->Parent;
  567.             if (y->Parent == NIL)
  568.                 *Tree = q;
  569.             else
  570.             {
  571.                 if (y == y->Parent->Left) {
  572.                     y->Parent->Left = q;
  573.                     q->Parent = y->Parent;
  574.                 }
  575.                 else {
  576.                     y->Parent->Right = q;
  577.                     q->Parent = y->Parent;
  578.                 }
  579.             }
  580.             if (y != p)
  581.             {
  582.                
  583.                 p->Data = y->Data;
  584.             }
  585.             if (y->red == false)
  586.                 DeleteFixup(q, *Tree, Tree);
  587.         }
  588.         (*Tree)->red = false;
  589.         delete(y);
  590.     }
  591.  
  592.     void Delfix(RBTree* p, RBTree **Tree)
  593.     {
  594.         RBTree* s;
  595.         while (p != *Tree && p->red == false)
  596.         {
  597.             if (p->Parent->Left == p)
  598.             {
  599.                 s = p->Parent->Right;
  600.                 if (s->red == true)
  601.                 {
  602.                     s->red = false;
  603.                     p->Parent->red = true;
  604.                     Rotate_Left( Tree,p->Parent);
  605.                     s = p->Parent->Right;
  606.                 }
  607.                 if (s->Right->red == false && s->Left->red == false)
  608.                 {
  609.                     s->red = true;
  610.                     p = p->Parent;
  611.                 }
  612.                 else
  613.                 {
  614.                     if (s->Right->red == false)
  615.                     {
  616.                         s->Left->red = false;
  617.                         s->red = true;
  618.                         Rotate_Right(Tree,s);
  619.                         s = p->Parent->Right;
  620.                     }
  621.                     s->red = p->Parent->red;
  622.                     p->Parent->red = false;
  623.                     s->Right->red = false;
  624.                     Rotate_Left(Tree,p->Parent);
  625.                     p = *Tree;
  626.                 }
  627.             }
  628.             else
  629.             {
  630.                 s = p->Parent->Left;
  631.                 if (s->red == true)
  632.                 {
  633.                     s->red = false;
  634.                     p->Parent->red = true;
  635.                     Rotate_Right(Tree,p->Parent);
  636.                     s = p->Parent->Left;
  637.                 }
  638.                 if (s->Left->red == false && s->Right->red ==false)
  639.                 {
  640.                     s->red = true;
  641.                     p = p->Parent;
  642.                 }
  643.                 else
  644.                 {
  645.                     if (s->Left->red == false)
  646.                     {
  647.                         s->Right->red = false;
  648.                         s->red = true;
  649.                         Rotate_Left(Tree,s);
  650.                         s = p->Parent->Left;
  651.                     }
  652.                     s->red = p->Parent->red;
  653.                     p->Parent->red = false;
  654.                     s->Left->red = false;
  655.                     Rotate_Right(Tree,p->Parent);
  656.                     p = *Tree;
  657.                 }
  658.             }
  659.             p->red = false;
  660.             (*Tree)->red = false;
  661.         }
  662.     }
  663.        
  664.    
  665.  
  666.    
  667.  
  668. int main()
  669. {
  670.     SetConsoleCP(1251);
  671.     SetConsoleOutputCP(1251);
  672.     /* int N, k;
  673.      cin >> N;
  674.      PNode root = NULL;
  675.      for (int i = 1; i <= N; i++)
  676.      {
  677.          cin >> k;
  678.          AddToTree(root, k);
  679.      }
  680.      PrintTree1(root);*/
  681.     GameObject* obj=NULL ;
  682.     NIL->Left = nullptr;
  683.     NIL->Right = nullptr;
  684.     NIL->obj = nullptr;
  685.     NIL->red = false;
  686.     //RBTree** Tree= NULL;
  687.     RBTree* New_Node = new RBTree();
  688.     New_Node = NIL;
  689.    
  690.    
  691.     int action = -1;
  692.     while (action != 0) {
  693.         cout << "1.Добавить элемент\n2.Удалить элемент\n3.Вывести элементы\n0.Выход" << endl;
  694.         int action;
  695.         cin >> action;
  696.         switch (action)
  697.         {
  698.         case 1: {
  699.             cout << "Введите тип игрового объекта: 1- снаряд, 2- транспортное средство, 3- танк, 4- самолёт" << endl;
  700.             int type;int ident=0;
  701.             cin >> type;
  702.             cout << "Введите идентификатор" << endl;;
  703.  
  704.             cin >> ident;
  705.             RBTree *result = FindItem(ident, New_Node);
  706.             while (result!=NIL) {
  707.                 cout << "Элемент с таким идентификатором уже существует" << endl;
  708.                 GameObject* obj = result->obj;
  709.                 ClassDefinition(obj);
  710.                 cout << "Введите идентификатор" << endl;
  711.                
  712.                 cin >> ident;
  713.                 result = FindItem(ident, New_Node);
  714.             }
  715.            
  716.             if (type == 1) {
  717.                 Projectile* p = new Projectile();
  718.                 p->UniqueIdentifier(ident);
  719.                 cout << "Укажите калибр" << endl;
  720.                 string caliber;
  721.                 cin >> caliber;
  722.                 cout << "Укажите вес" << endl;
  723.                 int weight;
  724.                 cin >> weight;
  725.                 p->Caliber(caliber);
  726.                 p->Weight(weight);
  727.                  obj = p;
  728.  
  729.  
  730.             }
  731.             else if (type == 2) {
  732.                 TransportVehicle* t = new  TransportVehicle();
  733.                 t->UniqueIdentifier(ident);
  734.                 cout << "Укажите мощность двигателя" << endl;
  735.                 int enginePower;
  736.                 cin >> enginePower;
  737.                 cout << "Укажите вес" << endl;
  738.                 int weight;
  739.                 cin >> weight;
  740.                 t->EnginePower(enginePower);
  741.                 t->Weight(weight);
  742.                 obj = t;
  743.             }
  744.             else if (type == 3) {
  745.                 Tank*tn =new Tank();
  746.                
  747.                 cout << "Укажите толщину брони" << endl;
  748.                 int armorThickness;
  749.                 cin >> armorThickness;
  750.                 cout << "Укажите текстуру" << endl;
  751.                 string texture;
  752.                 cin >> texture;
  753.                 cout << "Укажите мощность двигателя" << endl;
  754.                 int enginePower;
  755.                 cin >> enginePower;
  756.                 cout << "Укажите вес" << endl;
  757.                 int weight;
  758.                 cin >> weight;
  759.                 tn->EnginePower(enginePower);
  760.                 tn->Weight(weight);
  761.                 tn->ArmorThickness(armorThickness);
  762.                 tn->Texture(texture);
  763.                 tn->UniqueIdentifier(ident);
  764.                 obj = tn;
  765.             }
  766.             else {
  767.                 Airplane* a = new Airplane();
  768.                 a->UniqueIdentifier(ident);
  769.                
  770.                 cout << "Грузоподъёмность" << endl;
  771.                 int loadCapacity;
  772.                 cin >> loadCapacity;
  773.                 cout << "Укажите текстуру" << endl;
  774.                 string texture;
  775.                 cin >> texture;
  776.                 cout << "Укажите мощность двигателя" << endl;
  777.                 int enginePower;
  778.                 cin >> enginePower;
  779.                 cout << "Укажите вес" << endl;
  780.                 int weight;
  781.                 cin >> weight;
  782.                 a->EnginePower(enginePower);
  783.                 a->Weight(weight);
  784.                 a->LoadCapacity(loadCapacity);
  785.                 a->Texture(texture);
  786.                 obj = a;
  787.             }
  788.            
  789.             //int s = *d;
  790.             Insert_Node(&New_Node, obj);
  791.             break;
  792.  
  793.         }
  794.         case 2: {
  795.             cout << "Введите идентификатор" << endl;
  796.             int ident;
  797.             cin >> ident;
  798.            
  799.            
  800.                 DeleteNode(ident, &New_Node);
  801.            
  802.             break;
  803.         }
  804.         case 3: {
  805.             cout << "1- прямой обход, 2- обратный обход, 3- симметричный обход" << endl;
  806.             int bypass;
  807.             cin >> bypass;
  808.            
  809.             if (bypass == 1) {
  810.                 PreOrder_RBTree(New_Node);
  811.                 cout << endl;
  812.             }
  813.             else if (bypass == 2) {
  814.                 PostOrder_RBTree(New_Node);
  815.                 cout << endl;
  816.             }
  817.             else SymmetricOrder_RBTree(New_Node); {
  818.                 cout << endl; }
  819.             PrintTree1(New_Node);
  820.             cout << endl;
  821.             break;
  822.         }
  823.         case 0: {
  824.             delete (obj);
  825.             Delete_RBTree(New_Node);
  826.             return 0;
  827.         }
  828.         default:
  829.             break;
  830.         }
  831.     }
  832. }
  833.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement