czlowiekzgon

Untitled

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