DictionariesExampleThe following program reads strings from standard input (cin) and stores for each string the number of occurrences in adictionary D.
Finally it outputs all strings in D and their multiplicity.
#include <LEDA/core/dictionary.h> #include <LEDA/core/string.h> using namespace leda; int main() { dictionary<string,int> D; //objects of type int, keys of type string string s; dic_item it; do { std::cout << "Insert String ('stop' terminates loop): "; std::cin >> s; it=D.lookup(s); if (it==nil) D.insert(s,1); else D.change_inf(it,D.inf(it)+1); } while (s!="stop"); forall_items(it,D) { std::cout << D.key(it) << " " << D.inf(it) << std::endl; } return 0; } Strengths
Disadvantages
Tips
|
See also:Other data types with key of linearly ordered type: Data type with key of type pointer, item, or int: Maps Data type with key of hashed type: Hashing Arrays Manual Entries: |