good evening I was wondering if someone could walk me through creating a find and insert functions for the following class

//map of characters
//class to create a map of words, character at a time and allow access to each character and store a list of lines 
//from the input which the word is stored
class IndexClass 
{
 public:
    IndexClass() {};
    void insert(const string word, const int page);
    vector<int> findPages(const string word); 
 private:
    vector<int> pages;               // list of pages
    map <char, IndexClass *> next;   // pointer to next letter
	list <IndexClass> indexList;

};

I can add functionality to the class but not get rid of anything sadly. I have been wracking my brain for 4 days straight now but I can't come to think of how to link the different instances of indexclass to access the map for each and keep track of them/move around them. sadly I don't understand pointers well enough it seems and cannot seem to find any examples on google which answer my troubles.
but essentially I need to insert word which have been formatted to lower case with no punctuation into a series of maps each with a key of the characters in the word one at a time with the data being a pointer to another instance of indexclass. and finally at the last node amend pages but adding the page the word is on. and somehow check to see if the word has been entered before. any tips or tutorials you could link to would be GREATLY appreciated.

//Pre: Instance of IndexClass created
//Post: word entered into the map one character at a time along with line appeared on
void IndexClass::insert(const string word, const int page)
{	
	IndexClass *root, *node;
	int currentLetter=0;

 if( head == NULL )
   {
        head = new IndexClass;
		head->next[word[0]]=NULL;
		cout<<"RootCalled"<<endl;
   }
   else
   {
        root = head;
		
      while( root->next[word[currentLetter]] != NULL )
	  {
           root = root->next[word[currentLetter]];
			currentLetter++;
	  }
      node = new IndexClass;
      node->pages.push_back(page);
	  node->next[word[currentLetter]] = NULL;
      root->next[word[currentLetter]]= node;
	  for(int test=0; test<pages.size();test++)
	  {
		  cout<<"Pages: "<<node->pages[test]<<" ";
	  }
	  cout<<endl;
   }
	

}

//pre: Instance of Index class created and map filled
//post: return vector with lines the word appears on.
vector<int> IndexClass::findPages(const string word)
{
	IndexClass *root;
	int currentLetter=0;
	for( root=head; root!=NULL; root = root->next[word[currentLetter]])
	{
		for(int temp=0; temp<pages.size();temp++)
		{
			cout<<endl<<"Pages: "<<root->pages[temp]<<" ";
		}
		cout<<endl;
		currentLetter++;
	}
	//When you run out of letters, you read off the vector of lines numbers where it appears
	return pages;

}

so this is what I have so far for an implementation however the insert function is not quite working right and goes to root every other letter which I have no clue why it does so and it is not inserting the page into the vector for the last instance. any debugging help would be greatly appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.