// *****************************************************
// *                                                   *
// *   word.h (MP6)                                    *   
// *                                                   *
// *   Interface for a key/info class                  * 
// *                                                   *
// *   Written 2 March 1999 by Jason Zych              * 
// *  						       *
// *   Modified:  March 28 1999 		       * 
// *     Author:  Zaczek, Mariusz                      *
// *                                                   *
// *       - added: operator<<, operator>> & AVL tree  *
// *                                                   * 
// *****************************************************

#include <fstream.h>
#include "keypair.h"
#include "string.h"
#include "bstree.h"
#include "avltree.h"

class WordCounter
{
public:

   // WordCounter
   //    - default constructor
   //    - initializes object to default values
   WordCounter(); 


   // InsertWord
   //    - parameters : insWord - word to be inserted into tree
   //    - inserts word into tree with a count of 1. If word is 
   //       already in the tree, then simply increase the count
   //       of the word. 
   void InsertWord(String insWord); 


   // PrintFullInfo
   //    - prints the words in tree in alphabetical order,
   //        and along with the words, prints their counts.
   void PrintFullInfo() const;


   // PrintWordInfo
   //    - parameters : searchWord - word whose info will be printed 
   //    - print searchWord and its count  
   void PrintWordInfo(String searchWord);


   // WriteToFile
   //    - parameters : fileName - the name of the file to open and
   // 				write to
   //    - writes to the file indicated by the parameter. Will create
   // 				file if no such file exists.
   void WriteToFile(char* fileName);


   // ReadFrom File
   //    - parameters : fileName - the name of the file to open and
   //                             read from
   //    - reads from the file indicated by the parameter 
   void ReadFromFile(char* fileName); 


   // operator<<
   //    - parameters : Out - an ostream reference
   //                 : outputWord - a WordCounter to write to output
   //    - return value : an ostream reference
   //    - writes the given WordCounter to the given output stream
   //       ...this includes writing the BS and AVL trees
   friend ostream& operator<<(ostream& Out, const WordCounter& outputWord);


   // operator>>
   //    - parameters : In - an istream reference
   //                 : inputWord - a WordCounter to read from input
   //    - return value : an istream reference
   //    - reads the given WordCounter from the given input stream
   //       ... this includes reading the BS and AVL trees
   friend istream& operator>>(istream& In, WordCounter& inputWord);


private:

   BSTree<KeyPair<String, int> > countContainer;  // tree to hold keypair
					          //   objects for fast
						  //   lookup


   AVLTree<KeyPair<String, int> > AVLContainer;   // tree to hold keypair
                                                  //   object of AVL tree
                                                  //   for fast loopup

};

   


