Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <stack>
  4.  
  5. class Tree
  6. {
  7. private:
  8.     struct __Tree
  9.     {
  10.         char * word;
  11.         __Tree * left, * right;
  12.     } * Root;
  13.  
  14.     unsigned int __size;
  15.  
  16.     void recursivePrint( __Tree ** root );
  17.     void recursiveClean( __Tree ** root );
  18.  
  19. public:
  20.  
  21.     __Tree * end();
  22.     __Tree * begin();
  23.  
  24.     class iterator
  25.     {
  26.     private:
  27.         std::stack<__Tree *> Stack;
  28.         __Tree * pointer, * Root;
  29.     public:
  30.         iterator( Tree obj )
  31.         {
  32.             pointer = Root = obj.Root;
  33.             while( pointer->left != NULL )
  34.             {
  35.                 Stack.push( pointer );
  36.                 pointer = pointer->left;
  37.             }
  38.         }
  39.         ~iterator()
  40.         {
  41.             Stack.empty();
  42.         }
  43.         const char * operator * () const
  44.         {
  45.             return pointer->word;
  46.         }
  47.         bool operator++()
  48.         {
  49.  
  50.             if( pointer->right != NULL )
  51.             {
  52.                 pointer = pointer->right;
  53.                 while( pointer->left != NULL )
  54.                 {
  55.                     Stack.push( pointer );
  56.                     pointer = pointer->left;
  57.                 }
  58.             }
  59.             else
  60.             {
  61.                 if( Stack.size() > 0 )
  62.                 {
  63.                     pointer = Stack.top();
  64.                     Stack.pop();
  65.                 }
  66.                 else
  67.                     return false;
  68.             }
  69.             return true;
  70.         }
  71.     };
  72.  
  73.     Tree();
  74.     void print();
  75.     void clean();
  76.     unsigned int size();
  77.     bool insert( char * word );
  78. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement