Lecture 4
sequential containers
vector grid queue stack
Associative containers
map set(no values, just keys) lexicon(word/string supported set)
function to compile map

void compileMap(Map<string, int>& map, ifstream& infile) {
   while(true) {
      string word;
      cin>>word;
      if(infile.fail())  return;
      if(map.containsKey(word)) {
         map.put(word, mapget(word) +1);
      } else {
         map.put(word,1)
      }
   }

is same as:

void compileMap(Map<string, int>& map, ifstream& infile) {
   while(true) {
      string word;
      cin>>word;
      if(infile.fail())  return;
      map[word]++;
   }

printing out the map into a file

void printToFile(Map<string, int>& map, ofstream& outfile) {
   foreach(string key in map){
      outfile<<key<<": " << map[key] << endl;
   }
}

Building the map for anagrams

void buildAnagramsMap(Map <string, vector<string> >& anagrams) {
   Lexicon english("EnglishWords.dat");
   foreach(string word in english) {
      string key = characterSort(word);
      anagrams[key].add(word);
   }
}

   Login to remove ads X
Feedback | How-To