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

  1.  
  2. // This programs is using dictionaries with keys of type "string" with two 
  3. // different linear orders, the lexicographic ordering  (default ordering)
  4. // and the reversed lexicographic ordering 
  5.  
  6.  
  7. #include <LEDA/dictionary.h>
  8.  
  9.  
  10. int rev_cmp(string& x, string& y) 
  11. {
  12.   return compare(y,x);               // predefined compare function   
  13.   
  14.  }
  15.  
  16.  
  17. declare(STRING,rev_cmp);
  18.  
  19. // Now "STRING(rev_cmp)" is equivalent to the data type  string
  20. // with the linear order defined by "rev_cmp".
  21.  
  22.  
  23. declare2(dictionary,string,int)           // default ordering (by compare)
  24. declare2(dictionary,STRING(rev_cmp),int)  // ordering by rev_cmp
  25.  
  26.  
  27.  
  28. main()
  29. {
  30.   dictionary(string,int)           D;
  31.   dictionary(STRING(rev_cmp),int) D_rev;
  32.  
  33.   string x;
  34.  
  35.   while (cin >> x) 
  36.   { D.insert(x,0);
  37.     D_rev.insert(x,0);
  38.    }
  39.  
  40.   dic_item it;
  41.  
  42.   forall_dic_items(it,D) cout << D.key(it)  << "\n";
  43.   newline;
  44.  
  45.   forall_dic_items(it,D_rev) cout << D_rev.key(it)  << "\n";
  46.   newline;
  47.  
  48. }
  49.