OK here is the full code:
Code:
#include <algorithm>
#include <iostream>
#include <list>
#include <set>
#include <string>
using namespace std;
int main()
{
typedef set<string> WordSet;
typedef WordSet::iterator WordIter;
typedef list<WordIter> Index;
WordSet words;
Index input_order;
// Input the words uniquely
for(string new_word; cin >> new_word, new_word!="Quit"; )
{
const pair<WordIter,bool> &trace = words.insert(new_word);
if (trace.second)
input_order.push_back(trace.first);
}
// Output unique words in order of input:
cout << "\n>>> Unique words in input order:\n";
for (Index::iterator p = input_order.begin(); p!=input_order.end(); ++p)
{
cout << *(*p) << '\n';
}
// Output unique words in default set<string> order:
cout << "\n>>> Unique words in sorted order:\n";
copy(words.begin(), words.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}
this is code i found "somewhere"..
i figured almost evrything out of it but 1 thing..
why is he using pair?
why does he needs a bool there?
Argh!
im confused...
Luigi