home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / man / prog / dic.pro < prev    next >
Encoding:
Text File  |  1991-11-15  |  771 b   |  27 lines

  1. Using a dictionary to count the number of occurrences of the elements in 
  2. a sequence of strings, terminated by string ``stop''.
  3. \smallskip
  4. \#include $<$LEDA/dictionary.h$>$
  5. \smallskip
  6. {\bf declare2}(dictionary, string, int)
  7. \smallskip
  8. \cleartabs
  9. \+main()\cr
  10. \+$\{$\ \ &\cr
  11. \+  &dictionary(string, int) $D$;\cr
  12. \smallskip
  13. \+  &string $s$;\cr
  14. \+  &dic\_item $it$;\cr
  15. \smallskip
  16. \+  &{\bf while} &( (cin $>> s$) \&\& ($s$ != ``stop'') )\cr
  17. \+  &\ \  &$\{$ &$it = D$.lookup($s$);\cr
  18. \+  &     &    &if ($it==nil$) $D$.insert($s,1$);\cr
  19. \+  &     &    &else $D$.change\_inf($it$,$D$.info($it$)+1);\cr
  20. \+  &     &\ $\}$\cr
  21. \smallskip
  22. \+  &{\bf forall\_dic\_items}($it,D$) 
  23. cout $<< D$.info($it$) $<<$ ``  " $<<$  $D$.key($it$) $<<$ ``$\backslash$n";\cr
  24. \smallskip
  25. \+\ $\}$\cr
  26.  
  27.