home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / prog / basic / hash_dic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  376 b   |  25 lines

  1. #include <LEDA/hash.h>
  2.  
  3. declare2(hash,string,int)
  4.  
  5. int hash_fun(string& x) { return int(x[0]); }
  6.  
  7. main()
  8.  
  9. {
  10.   hash(string,int) D(hash_fun);
  11.  
  12.   hash_item it;
  13.   string r;
  14.  
  15.   while (cin >> r)
  16.     { it = D.lookup(r);
  17.       if (it==nil) D.insert(r,1);
  18.       else D.change_inf(it,D.info(it)+1);
  19.      }
  20.  
  21.   forall_hash_items(it,D) cout <<  D.info(it) << " " << D.key(it) << "\n";
  22.  
  23. }
  24.  
  25.