title: Print all words in Alphabetical order from trie
body: <p>I am pretty new to tries. I found some solutions on net, but tries are defined in totally different way. I need solution for this type of trie. </p>
  
  <p>What I need is function to print all words from trie in alphabetical order. As you can see, Insert and Search functions are done. Here is 2 header files, necessary for main code.</p>
  
  <p>EntryType.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  const int MAXLENGTH = 10;
  class EntryType
  {
  public:
      EntryType();
      EntryType(char * key);
      EntryType(EntryType &amp; entry);
      ~EntryType();
      bool operator== (const EntryType&amp; item) const;
      bool operator!= (const EntryType&amp; item) const;
      friend istream&amp; operator&gt;&gt; (istream&amp; is, EntryType&amp; item);
      friend ostream&amp; operator&lt;&lt; (ostream&amp; os, EntryType item);
      void EntryKey(char word[]);
      void PrintWord();
  
  private:
      char entryKey[MAXLENGTH];
  };
  
  ostream&amp; operator&lt;&lt; (ostream&amp; os, EntryType item)
  {
      os &lt;&lt; item.entryKey;
      return os;
  }
  
  EntryType::EntryType()
  {
      // empty instance constructor
  }
  EntryType::~EntryType()
  {
      // destructor
  }
  
  void EntryType::EntryKey(char word[])
  {
      for (int i = 0; i &lt; 10; i++)
      {
          entryKey[i] = word[i];
      }
  }
  
  void EntryType::PrintWord()
  {
      cout &lt;&lt; entryKey &lt;&lt; endl;
  }
  </code></pre>
  
  <p>TrieType.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include "EntryType.h"
  
  
  const int LETTERS = 26;
  typedef char Key[MAXLENGTH];
  struct Trienode
  {
      Trienode *branch[LETTERS];
      EntryType *ref;
  };
  
  class TrieType
  {
  
  private:
      Trienode * root;
  
  public:
      TrieType();
      ~TrieType();
      TrieType(TrieType &amp;originalTree);
      void operator=(TrieType &amp; originalTree);
      void MakeEmpty();
      void InsertTrie(Key newkey, EntryType *newentry);
      EntryType *  TrieSearch(Key target);
      bool DeleteTrie(Key delkey);
      void PrintTrie();
  };
  
  TrieType::TrieType()
  {
      root = NULL;
  }
  
  
  TrieType::~TrieType()
  {
      // destructor
  }
  TrieType::TrieType(TrieType &amp;originalTree)
  {
      // constructor
  }
  
  EntryType *TrieType::TrieSearch(Key target)
  {
      int i;
      Trienode * current = root;
      for (i = 0; i &lt; MAXLENGTH &amp;&amp; current; i++)
      if (target[i] == '\0')
          break;
      else
          current =
          current-&gt;branch[target[i] - 'a'];
      if (!current)
          return NULL;
      else
      if (!current-&gt;ref)
          return NULL;
  
      return current-&gt;ref;
  }
  
  
  Trienode *CreateNode()
  {
      int ch;
      Trienode *newnode = new Trienode;
      for (ch = 0; ch &lt; LETTERS; ch++)
          newnode-&gt;branch[ch] = NULL;
  
      newnode-&gt;ref = NULL;
  
      return newnode;
  }
  
  void TrieType::InsertTrie(Key newkey, EntryType *newentry)
  {
      int i;
      Trienode *current;
      if (!root)
          root = CreateNode();
      current = root;
      for (i = 0; i &lt; MAXLENGTH; i++)
      if (newkey[i] == '\0')
          break;
      else
      {
          if (!current-&gt;branch[newkey[i] - 'a'])
              current-&gt;branch[newkey[i] - 'a'] = CreateNode();
          current = current-&gt;branch[newkey[i] - 'a'];
      }
      if (current-&gt;ref != NULL)
          cout &lt;&lt; "\nTried to insert a duplicate key." &lt;&lt; endl;
      else
          current-&gt;ref = newentry;
  }
  </code></pre>