Advertisement
Auios

Untitled

Dec 9th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. iterator begin() {
  2.         Node* cr = this->root;
  3.         bool flag = false;
  4.         while (cr && !flag) {
  5.             if (cr->left && !cr->leftThreaded) {
  6.                 cr = cr->left;
  7.             }
  8.             else flag = true;
  9.         }
  10.         return iterator(cr, this);
  11.     }
  12.  
  13.     /*Returns an iterator to the node that follows the node with the biggest value.*/
  14.     iterator end() {
  15.         return iterator(nullptr, this);
  16.     }
  17.  
  18.     /*Returns a const_iterator that points to the node with the smallest value.*/
  19.     const_iterator cbegin()const {
  20.         Node* cr = this->root;
  21.         bool flag = false;
  22.         while (cr && !flag) {
  23.             if (cr->left && !cr->leftThreaded) {
  24.                 cr = cr->left; //if the node has a left child -> move left
  25.             }
  26.             else flag = true;
  27.         }
  28.         return const_iterator(cr, this);
  29.     }
  30.  
  31.     /*Returns a const_iterator to the node that follows the node with the biggest value.*/
  32.     const_iterator cend() const {
  33.         return const_iterator(nullptr, this);
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement