list<string> lastNWords contains last N words, first being the one encountered 
most recently

// suppose following function gets called whenever a new word is encountered
void addNewWord(string newWord, map<words, list<string>::iterator>& mp, 
list<string>& lastNWords)
{
    lastNWords.push_front(newWord);
     if(mp.find(newWord) != mp.end()) {
         // newWord is already there
         lastNWords.erase(mp[newWord]);
         mp[newWord] = list.begin();
     } else {
        lastNWords.erase(lastNWords.rbegin());
     }
}




________________________________
From: richa gupta <richa.cs...@gmail.com>
To: algogeeks@googlegroups.com
Sent: Friday, 14 August, 2009 12:53:46 PM
Subject: [algogeeks] Question asked in MS interview


You have to develop a piece of code that can be attached to a program
like Microsoft Word, which would list the last "N" words of the
document in descending order of their occurence, and update the list
as the user types. What code would you write? Using pseudo code is
fine, just list the basic things you would consider

-- 
Richa Gupta
(IT-BHU,India)



      Yahoo! recommends that you upgrade to the new and safer Internet Explorer 
8. http://downloads.yahoo.com/in/internetexplorer/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to