Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <stack>
- class Tree
- {
- private:
- struct __Tree
- {
- char * word;
- __Tree * left, * right;
- } * Root;
- unsigned int __size;
- void recursivePrint( __Tree ** root );
- void recursiveClean( __Tree ** root );
- public:
- __Tree * end();
- __Tree * begin();
- class iterator
- {
- private:
- std::stack<__Tree *> Stack;
- __Tree * pointer, * Root;
- public:
- iterator( Tree obj )
- {
- pointer = Root = obj.Root;
- while( pointer->left != NULL )
- {
- Stack.push( pointer );
- pointer = pointer->left;
- }
- }
- ~iterator()
- {
- Stack.empty();
- }
- const char * operator * () const
- {
- return pointer->word;
- }
- bool operator++()
- {
- if( pointer->right != NULL )
- {
- pointer = pointer->right;
- while( pointer->left != NULL )
- {
- Stack.push( pointer );
- pointer = pointer->left;
- }
- }
- else
- {
- if( Stack.size() > 0 )
- {
- pointer = Stack.top();
- Stack.pop();
- }
- else
- return false;
- }
- return true;
- }
- };
- Tree();
- void print();
- void clean();
- unsigned int size();
- bool insert( char * word );
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement