Advertisement
czlowiekzgon

Untitled

Dec 7th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.65 KB | None | 0 0
  1. //SDIZO I1 222A LAB04
  2. //Paweł Patyk
  3. //pp41473@zut.edu.pl
  4.  
  5. #include "pch.h"
  6. #include <iostream>
  7. #include <sstream>
  8. #include <string>
  9. #include <cstdlib>
  10. #include <ctime>
  11. #include <fstream>
  12. #include <math.h>
  13. using namespace std;
  14.  
  15.  
  16. class Element {
  17. private:
  18. int key;
  19. int balance;
  20. Element *ptrLeft;
  21. Element *ptrRight;
  22. char tab[10];
  23. public:
  24. Element();
  25. Element(int keyVal);
  26. ~Element();
  27. int getKey();
  28. int getBalance();
  29. Element * getPtrLeft();
  30. Element * getPtrRight();
  31. char * getTab();
  32.  
  33. void setPtrLeft(int liczba);
  34. void setPtrLeft(Element *ptr);
  35. void setPtrRight(int liczba);
  36. void setPtrRight(Element *ptr);
  37. void increaseBalance();
  38. void reduceBalance();
  39.  
  40.  
  41. };
  42.  
  43. Element::Element() {
  44.  
  45. }
  46.  
  47. Element::Element(int keyVal) {
  48. key = keyVal;
  49. sprintf_s(tab, "%d", keyVal);
  50. balance = 0;
  51. }
  52.  
  53.  
  54. Element ::~Element() {
  55.  
  56. }
  57.  
  58. int Element::getKey() {
  59. return this->key;
  60. }
  61.  
  62. int Element::getBalance() {
  63. return this->balance;
  64. }
  65.  
  66. Element * Element::getPtrLeft() {
  67. return this->ptrLeft;
  68. }
  69.  
  70. Element * Element::getPtrRight() {
  71. return this->ptrRight;
  72. }
  73.  
  74. char * Element::getTab() {
  75. return tab;
  76. }
  77.  
  78. void Element::setPtrLeft(int liczba) {
  79. ptrLeft = new Element(liczba);
  80. }
  81.  
  82. void Element::setPtrRight(int liczba) {
  83. ptrRight = new Element(liczba);
  84. }
  85.  
  86.  
  87. void Element::setPtrLeft(Element * ptr) {
  88. ptrLeft = ptr;
  89. }
  90.  
  91. void Element::setPtrRight(Element * ptr) {
  92. ptrRight = ptr;
  93. }
  94.  
  95. void Element::increaseBalance() {
  96. balance++;
  97. }
  98.  
  99. void Element::reduceBalance() {
  100. balance--;
  101. }
  102.  
  103.  
  104.  
  105.  
  106.  
  107. class Tree {
  108. private:
  109. Element * root = nullptr;
  110. int numberElements;
  111. public:
  112. Tree();
  113. Tree(int i);
  114. void setRoot(Element * ptr);
  115. void add(int keyVal);
  116. void addMany(int num);
  117. bool find(int key_val, bool kom = true);
  118. void remove(int key_val);
  119.  
  120. void rotateRight(Element * ptrGrand, Element * ptrPar, Element * ptrChild);
  121. void rotateLeft(Element * ptrGrand, Element * ptrPar, Element * ptrChild);
  122. void showPreorder();
  123. void showPreorder(Element * ptr, int &i);
  124. void showInorder();
  125. void showInorder(Element * ptr, int &i);
  126. void showPostorder();
  127. void showPostorder(Element * ptr, int &i);
  128. void showNumberElements();
  129. };
  130.  
  131. Tree::Tree() {
  132.  
  133. }
  134.  
  135. void Tree::setRoot(Element * ptr) {
  136. root = ptr;
  137. }
  138.  
  139.  
  140.  
  141. void Tree::showPreorder(Element * ptr, int &i) {
  142. if (ptr == nullptr) {
  143. return;
  144. }
  145. else {
  146. i++;
  147. cout << ptr->getKey() << endl;
  148. showPreorder(ptr->getPtrLeft(), i);
  149. showPreorder(ptr->getPtrRight(), i);
  150. }
  151. }
  152.  
  153. void Tree::showPreorder() {
  154. int i = 0;
  155. if (root == nullptr) {
  156. cout << "nie mozna wyswietlic korzen jest pusty" << endl;
  157. }
  158. else {
  159. showPreorder(root, i);
  160. cout << "liczba odwiedzanych wezlow : " << i << endl;
  161. }
  162. }
  163.  
  164. void Tree::showInorder(Element * ptr, int &i) {
  165. if (ptr == nullptr) {
  166. return;
  167. }
  168. else {
  169. i++;
  170. showInorder(ptr->getPtrLeft(), i);
  171. cout << ptr->getKey() << endl;
  172. showInorder(ptr->getPtrRight(), i);
  173. }
  174. }
  175.  
  176. void Tree::showInorder() {
  177. int i = 0;
  178.  
  179. if (root == nullptr) {
  180. cout << "nie mozna wyswietlic korzen jest pusty" << endl;
  181. }
  182. else {
  183. showInorder(root, i);
  184. cout << "liczba odwiedzanych wezlow : " << i << endl;
  185. }
  186. }
  187.  
  188.  
  189.  
  190. void Tree::showPostorder(Element * ptr, int &i) {
  191. if (ptr == nullptr) {
  192. return;
  193. }
  194. else {
  195. i++;
  196. showPostorder(ptr->getPtrLeft(), i);
  197. showPostorder(ptr->getPtrRight(), i);
  198. cout << ptr->getKey() << endl;
  199. }
  200. }
  201.  
  202.  
  203. void Tree::showPostorder() {
  204. int i = 0;
  205. if (root == nullptr) {
  206. cout << "nie mozna wyswietlic korzen jest pusty" << endl;
  207. }
  208. else {
  209. showPostorder(root, i);
  210. cout << "liczba odwiedzanych wezlow : " << i << endl;
  211. }
  212. }
  213.  
  214.  
  215. void Tree::showNumberElements() {
  216. cout << "Liczba elementow : " << numberElements << endl;
  217. }
  218.  
  219.  
  220. bool Tree::find(int key_val, bool kom) {
  221. Element * supPtr = root;
  222. if (root == nullptr) {
  223. if (kom == true) {
  224. cout << "korzen jest pusty" << endl;
  225. }
  226. return false;
  227. }
  228. if (supPtr->getKey() == key_val) {
  229. if (kom == true) {
  230. cout << "istnieje element z podanym kluczem " << endl;
  231. }
  232. return true;
  233. }
  234. else if (supPtr->getKey() > key_val) {
  235. supPtr = supPtr->getPtrLeft();
  236. }
  237. else if (supPtr->getKey() < key_val) {
  238. supPtr = supPtr->getPtrRight();
  239. }
  240.  
  241. while (supPtr != nullptr) {
  242. if (supPtr->getKey() == key_val) {
  243. if (kom == true) {
  244. cout << "istnieje element z podanym kluczem " << endl;
  245. }
  246. return true;
  247. }
  248. else if (supPtr->getKey() > key_val) {
  249. supPtr = supPtr->getPtrLeft();
  250. }
  251. else if (supPtr->getKey() < key_val) {
  252. supPtr = supPtr->getPtrRight();
  253. }
  254. }
  255. if (supPtr == nullptr) {
  256. if (kom == true) {
  257. cout << "nie ma elementu o podanym kluczu " << endl;
  258. }
  259. return false;
  260. }
  261. }
  262.  
  263. void Tree::rotateRight(Element * ptrGrand, Element * ptrPar, Element * ptrChild) {
  264. if (ptrGrand != nullptr) {
  265. if (ptrGrand->getPtrRight() == ptrPar) {
  266. ptrGrand->setPtrRight(ptrChild);
  267. }
  268. else {
  269. ptrGrand->setPtrLeft(ptrChild);
  270. }
  271. }
  272. else {
  273. root = ptrChild;
  274. }
  275. Element *ptrSup = ptrChild->getPtrRight();
  276. ptrChild->setPtrLeft(ptrPar);
  277. ptrPar->setPtrRight(ptrSup);
  278.  
  279.  
  280. }
  281.  
  282.  
  283. void Tree::rotateLeft(Element * ptrGrand, Element * ptrPar, Element * ptrChild) {
  284. if (ptrGrand != nullptr) {
  285. if (ptrGrand->getPtrRight() == ptrPar) {
  286. ptrGrand->setPtrRight(ptrChild);
  287. }
  288. else {
  289. ptrGrand->setPtrLeft(ptrChild);
  290. }
  291. }
  292. else {
  293. root = ptrChild;
  294. }
  295. Element *ptrSup = ptrChild->getPtrLeft();
  296. ptrChild->setPtrRight(ptrPar);
  297. ptrPar->setPtrLeft(ptrSup);
  298.  
  299.  
  300. }
  301.  
  302. void Tree::add(int keyVal) {
  303.  
  304. bool czy_sie_powtarza = find(keyVal, false);
  305. if (czy_sie_powtarza == true) {
  306. cout << "nie mozna dodac obikektu poniewaz istnieje juz jeden z takim kluczem" << endl;
  307. return;
  308. }
  309.  
  310. if (root == nullptr) {
  311. root = new Element(keyVal);
  312. numberElements++;
  313. return;
  314. }
  315.  
  316.  
  317.  
  318. Element * supPtr = root;
  319. int sizeArray = log2(numberElements) + 1;
  320. Element **tabPtr = new Element *[sizeArray];
  321. for (int i = 0; i < sizeArray; i++) {
  322. tabPtr[i] = nullptr;
  323. }
  324.  
  325.  
  326.  
  327. for (int i = 0; i < sizeArray; i++) {
  328. tabPtr[i] = supPtr;
  329. if (supPtr->getKey() > keyVal && supPtr->getPtrLeft() != nullptr) {
  330. supPtr->reduceBalance();
  331. supPtr = supPtr->getPtrLeft();
  332. }
  333. else if (supPtr->getKey() < keyVal && supPtr->getPtrRight() != nullptr) {
  334. supPtr->increaseBalance();
  335. supPtr = supPtr->getPtrRight();
  336. }
  337. else if (supPtr->getKey() > keyVal && supPtr->getPtrLeft() == nullptr) {
  338.  
  339. supPtr->reduceBalance();
  340.  
  341. supPtr->setPtrLeft(keyVal);
  342. break;
  343. }
  344. else if (supPtr->getKey() < keyVal && supPtr->getPtrRight() == nullptr) {
  345.  
  346. supPtr->increaseBalance();
  347. supPtr->setPtrRight(keyVal);
  348. break;
  349. }
  350. }
  351.  
  352. for (int i = sizeArray; i > 0; i--) {
  353. if (tabPtr[i] != nullptr) {
  354. //cout << tabPtr[i]->getKey() << " " << tabPtr[i]->getBalance() << endl;
  355. if (tabPtr[i]->getBalance() == 2) {
  356. //cout << "Wykonalo sie" << endl;
  357. Element * ptrGrand = tabPtr[i];
  358. Element * ptrPar = ptrGrand->getPtrRight();
  359. Element * ptrChild = ptrPar->getPtrRight();
  360.  
  361. rotateLeft(ptrGrand, ptrPar, ptrChild);
  362.  
  363. }
  364.  
  365.  
  366.  
  367. }
  368.  
  369. }
  370.  
  371.  
  372. numberElements++;
  373. //for (int i = 0; i < sizeArray; i++) {
  374. // if (tabPtr[i] == nullptr) {
  375. // break;
  376. // }
  377. //
  378.  
  379.  
  380. // //cout << tabPtr[i]->getBalance() << " " << tabPtr[i]->getKey() << endl;
  381. //}
  382. //cout << endl;
  383. }
  384.  
  385.  
  386.  
  387.  
  388. int main()
  389. {
  390.  
  391.  
  392. Tree tree;
  393. tree.add(10);
  394. tree.add(5);
  395. tree.add(20);
  396. tree.add(3);
  397. tree.add(6);
  398. tree.add(15);
  399. tree.add(25);
  400. tree.add(30);
  401. tree.add(4);
  402. tree.showPreorder();
  403. cout << endl;
  404. cout << endl;
  405. tree.add(40);
  406. tree.showPreorder();
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414. }
  415.  
  416.  
  417.  
  418. //class Element {
  419. //
  420. //private:
  421. // int key;
  422. // Element * ptr_left = nullptr;
  423. // Element * ptr_right = nullptr;
  424. // char tab[10];
  425. // int balance;
  426. //public:
  427. // Element();
  428. // Element(int key_val);
  429. // int get_key();
  430. // Element * get_ptr_left();
  431. // Element * get_ptr_right();
  432. // void set_ptr_left(int liczba);
  433. // void set_ptr_right(int liczba);
  434. // void set_ptr_left(Element * ptr);
  435. // void set_ptr_right(Element * ptr);
  436. // char * show_tab();
  437. //
  438. //};
  439. //Element::Element() {
  440. //
  441. //}
  442. //
  443. //Element::Element(int key_val) {
  444. // key = key_val;
  445. // sprintf_s(tab, "%d", key_val);
  446. //}
  447. //
  448. //
  449. //
  450. //int Element::get_key() {
  451. // return key;
  452. //}
  453. //
  454. //Element * Element::get_ptr_left() {
  455. // return ptr_left;
  456. //}
  457. //
  458. //Element * Element::get_ptr_right() {
  459. // return ptr_right;
  460. //}
  461. //
  462. //void Element::set_ptr_left(int liczba) {
  463. // ptr_left = new Element(liczba);
  464. //}
  465. //
  466. //void Element::set_ptr_right(int liczba) {
  467. // ptr_right = new Element(liczba);
  468. //}
  469. //
  470. //
  471. //void Element::set_ptr_left(Element * ptr) {
  472. // ptr_left = ptr;
  473. //}
  474. //
  475. //void Element::set_ptr_right(Element * ptr) {
  476. // ptr_right = ptr;
  477. //}
  478. //
  479. //
  480. //char * Element::show_tab() {
  481. // return tab;
  482. //}
  483. //
  484. //class Tree {
  485. //private:
  486. // Element * root = nullptr;
  487. //
  488. //public:
  489. // Tree();
  490. // Tree(int i);
  491. // void set_root(Element * ptr);
  492. // void add(int key_val);
  493. // void add_many(int num);
  494. // bool find(int key_val, bool kom = true);
  495. // void remove(int key_val);
  496. // void show_pre_order();
  497. // void show_pre_order(Element * ptr, int &i);
  498. // void show_in_order();
  499. // void show_in_order(Element * ptr, int &i);
  500. // void show_post_order();
  501. // void show_post_order(Element * ptr, int &i);
  502. //};
  503. //
  504. //
  505. //
  506. //
  507. //
  508. //
  509. //
  510. //Tree::Tree() {
  511. //
  512. //}
  513. //
  514. //void Tree::set_root(Element * ptr) {
  515. // root = ptr;
  516. //}
  517. //
  518. //bool Tree::find(int key_val, bool kom) {
  519. // Element * sup_ptr = root;
  520. // if (root == nullptr) {
  521. // if (kom == true) {
  522. // cout << "korzen jest pusty" << endl;
  523. //
  524. // }
  525. // return false;
  526. // }
  527. // if (sup_ptr->get_key() == key_val) {
  528. // if (kom == true) {
  529. // cout << "istnieje element z podanym kluczem " << endl;
  530. //
  531. // }
  532. // return true;
  533. // }
  534. // else if (sup_ptr->get_key() > key_val) {
  535. // sup_ptr = sup_ptr->get_ptr_left();
  536. // }
  537. // else if (sup_ptr->get_key() < key_val) {
  538. // sup_ptr = sup_ptr->get_ptr_right();
  539. // }
  540. //
  541. // while (sup_ptr != nullptr) {
  542. // if (sup_ptr->get_key() == key_val) {
  543. // if (kom == true) {
  544. // cout << "istnieje element z podanym kluczem " << endl;
  545. // }
  546. // return true;
  547. // }
  548. // else if (sup_ptr->get_key() > key_val) {
  549. // sup_ptr = sup_ptr->get_ptr_left();
  550. // }
  551. // else if (sup_ptr->get_key() < key_val) {
  552. // sup_ptr = sup_ptr->get_ptr_right();
  553. // }
  554. // }
  555. // if (sup_ptr == nullptr) {
  556. // if (kom == true) {
  557. // cout << "nie ma elementu o podanym kluczu " << endl;
  558. //
  559. // }
  560. // return false;
  561. // }
  562. //}
  563. //
  564. //
  565. //void Tree::add(int key_val) {
  566. //
  567. // if (root == nullptr) {
  568. // root = new Element(key_val);
  569. // return;
  570. //
  571. // }
  572. //
  573. // bool czy_sie_powtarza = find(key_val, false);
  574. // if (czy_sie_powtarza == true) {
  575. // cout << "nie mozna dodac obikektu poniewaz istnieje juz jeden z takim kluczem" << endl;
  576. // return;
  577. // }
  578. //
  579. // Element * sup_ptr = root;
  580. //
  581. //
  582. // while ((sup_ptr->get_key() > key_val && sup_ptr->get_ptr_left() != nullptr) || (sup_ptr->get_key() < key_val && sup_ptr->get_ptr_right() != nullptr)) {
  583. // if (sup_ptr->get_key() > key_val) {
  584. // sup_ptr = sup_ptr->get_ptr_left();
  585. // }
  586. // else if (sup_ptr->get_key() < key_val) {
  587. // sup_ptr = sup_ptr->get_ptr_right();
  588. // }
  589. //
  590. // }
  591. // if (sup_ptr->get_key() > key_val) {
  592. // sup_ptr->set_ptr_left(key_val);
  593. // }
  594. // else if (sup_ptr->get_key() < key_val) {
  595. // sup_ptr->set_ptr_right(key_val);
  596. // }
  597. //
  598. //}
  599. //
  600. //void Tree::add_many(int num) {
  601. // for (int i = 0; i < num; i++) {
  602. // int key_val = (rand() % 20000) - 10000;
  603. // while (find(key_val, false) == true) {
  604. // key_val = (rand() % 20000) - 10000;
  605. // }
  606. // add(key_val);
  607. // }
  608. //
  609. //}
  610. //
  611. //
  612. //
  613. //void Tree::show_pre_order(Element * ptr, int &i) {
  614. // if (ptr == nullptr) {
  615. // return;
  616. // }
  617. // else {
  618. // i++;
  619. // cout << ptr->get_key() << endl;
  620. // show_pre_order(ptr->get_ptr_left(), i);
  621. // show_pre_order(ptr->get_ptr_right(), i);
  622. // }
  623. //}
  624. //
  625. //void Tree::show_pre_order() {
  626. // int i = 0;
  627. // if (root == nullptr) {
  628. // cout << "nie mozna wyswietlic korzen jest pusty" << endl;
  629. // }
  630. // else {
  631. // show_pre_order(root, i);
  632. // cout << "liczba odwiedzanych wezlow : " << i << endl;
  633. // }
  634. //}
  635. //
  636. //void Tree::show_in_order(Element * ptr, int &i) {
  637. // if (ptr == nullptr) {
  638. // return;
  639. // }
  640. // else {
  641. // i++;
  642. // show_in_order(ptr->get_ptr_left(), i);
  643. // cout << ptr->get_key() << endl;
  644. // show_in_order(ptr->get_ptr_right(), i);
  645. // }
  646. //}
  647. //
  648. //void Tree::show_in_order() {
  649. // int i = 0;
  650. //
  651. // if (root == nullptr) {
  652. // cout << "nie mozna wyswietlic korzen jest pusty" << endl;
  653. // }
  654. // else {
  655. // show_in_order(root, i);
  656. // cout << "liczba odwiedzanych wezlow : " << i << endl;
  657. // }
  658. //}
  659. //
  660. //
  661. //
  662. //void Tree::show_post_order(Element * ptr, int &i) {
  663. // if (ptr == nullptr) {
  664. // return;
  665. // }
  666. // else {
  667. // i++;
  668. // show_post_order(ptr->get_ptr_left(), i);
  669. // show_post_order(ptr->get_ptr_right(), i);
  670. // cout << ptr->get_key() << endl;
  671. // }
  672. //}
  673. //
  674. //
  675. //void Tree::show_post_order() {
  676. // int i = 0;
  677. // if (root == nullptr) {
  678. // cout << "nie mozna wyswietlic korzen jest pusty" << endl;
  679. // }
  680. // else {
  681. // show_post_order(root, i);
  682. // cout << "liczba odwiedzanych wezlow : " << i << endl;
  683. // }
  684. //}
  685. //
  686. //
  687. //void Tree::remove(int key_val) {
  688. // Element * ptr = root;
  689. // Element * par_ptr = nullptr;
  690. // if (root == nullptr) {
  691. // cout << " nie mozna usunac wezla ,korzen jest pusty" << endl;
  692. // return;
  693. // }
  694. // while (ptr != nullptr) {
  695. //
  696. // if (ptr->get_key() == key_val) {
  697. //
  698. // if (ptr->get_ptr_left() == nullptr && ptr->get_ptr_right() == nullptr) {
  699. // if (par_ptr->get_ptr_left() == ptr) {
  700. // if (root == ptr) {
  701. // delete ptr;
  702. // root = nullptr;
  703. // }
  704. // delete ptr;
  705. // par_ptr->set_ptr_left(nullptr);
  706. // return;
  707. // }
  708. // else {
  709. // if (root == ptr) {
  710. // delete ptr;
  711. // root = nullptr;
  712. // }
  713. // delete ptr;
  714. // par_ptr->set_ptr_right(nullptr);
  715. // return;
  716. // }
  717. // }
  718. //
  719. // else if (ptr->get_ptr_left() == nullptr && ptr->get_ptr_right() != nullptr) {
  720. // if (par_ptr->get_ptr_left() == ptr) {
  721. //
  722. // par_ptr->set_ptr_left(ptr->get_ptr_right());
  723. // delete ptr;
  724. // return;
  725. // }
  726. // else {
  727. //
  728. // par_ptr->set_ptr_right(ptr->get_ptr_right());
  729. // delete ptr;
  730. // return;
  731. // }
  732. // }
  733. // else if ((ptr->get_ptr_left() != nullptr && ptr->get_ptr_right() == nullptr)) {
  734. // if (ptr == root) {
  735. // Element * sup_ptr = ptr->get_ptr_left();
  736. // delete root;
  737. // root = sup_ptr;
  738. // return;
  739. // }
  740. // if (par_ptr->get_ptr_left() == ptr) {
  741. //
  742. // par_ptr->set_ptr_left(ptr->get_ptr_left());
  743. // delete ptr;
  744. // return;
  745. // }
  746. // else {
  747. //
  748. // par_ptr->set_ptr_right(ptr->get_ptr_left());
  749. // delete ptr;
  750. // return;
  751. // }
  752. // }
  753. // else if ((ptr->get_ptr_left() != nullptr && ptr->get_ptr_right() != nullptr)) {
  754. //
  755. //
  756. //
  757. // Element *succes_ptr = ptr->get_ptr_right();
  758. // Element * par_succes_ptr = nullptr;
  759. // while (succes_ptr->get_ptr_left() != nullptr) {
  760. // par_succes_ptr = succes_ptr;
  761. // succes_ptr = succes_ptr->get_ptr_left();
  762. // }
  763. // if (succes_ptr->get_ptr_right() == nullptr) {
  764. // if (root == ptr && (ptr->get_ptr_right() == succes_ptr)) {
  765. //
  766. // }
  767. // else {
  768. // if (par_succes_ptr == nullptr) {
  769. // succes_ptr->set_ptr_left(ptr->get_ptr_left());
  770. // }
  771. // else
  772. // {
  773. // par_succes_ptr->set_ptr_left(nullptr);
  774. // }
  775. //
  776. // }
  777. //
  778. // }
  779. // else {
  780. // if (root == ptr && (ptr->get_ptr_right() == succes_ptr)) {
  781. //
  782. // }
  783. // else
  784. // {
  785. // if (par_succes_ptr == nullptr) {
  786. // succes_ptr->set_ptr_left(ptr->get_ptr_left());
  787. // }
  788. // else
  789. // {
  790. // par_succes_ptr->set_ptr_left(succes_ptr->get_ptr_right());
  791. // }
  792. //
  793. // }
  794. //
  795. // }
  796. //
  797. // succes_ptr->set_ptr_left(ptr->get_ptr_left());
  798. // if (ptr == root && (ptr->get_ptr_right() == succes_ptr)) {
  799. //
  800. // }
  801. // else {
  802. // if (par_succes_ptr == nullptr)
  803. // {
  804. // }
  805. // else
  806. // {
  807. // succes_ptr->set_ptr_right(ptr->get_ptr_right());
  808. // }
  809. //
  810. // }
  811. // if (ptr == root) {
  812. // delete root;
  813. // root = succes_ptr;
  814. // return;
  815. // }
  816. //
  817. // if (par_ptr->get_ptr_left() == ptr) {
  818. // par_ptr->set_ptr_left(succes_ptr);
  819. // delete ptr;
  820. // return;
  821. // }
  822. // else {
  823. // par_ptr->set_ptr_right(succes_ptr);
  824. // delete ptr;
  825. // return;
  826. // }
  827. //
  828. //
  829. // }
  830. //
  831. //
  832. // }
  833. // else if (ptr->get_key() > key_val) {
  834. // par_ptr = ptr;
  835. // ptr = ptr->get_ptr_left();
  836. // }
  837. // else {
  838. // par_ptr = ptr;
  839. // ptr = ptr->get_ptr_right();
  840. // }
  841. // }
  842. // cout << "nie mozna usunac wezla poniewaz nie istnieje " << endl;
  843. // return;
  844. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement