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

  1. #include <LEDA/list.h>
  2.  
  3.  
  4. declare(list,string)
  5.  
  6.  
  7. int cmp_length(string& x, string& y) 
  8. { return x.length() - y.length(); }
  9.  
  10.  
  11. int F(string& x)  
  12. { return  (x.length() > 0) ? int(x[0]) : 0; }
  13.  
  14.  
  15. main()
  16. { list(string) L;
  17.   string s;
  18.  
  19.   L.read("List of strings : ");
  20.   newline;
  21.  
  22. // random permutation
  23.   L.permute();
  24.   L.print("permuted: ");
  25.   newline;
  26.   newline;
  27.  
  28.  
  29. // sort lexicographically
  30.  
  31.   L.sort(compare);                        // predefined compare(string&,string&)
  32.   L.print("sorted lexicographically:\n");
  33.   newline;
  34.   newline;
  35.  
  36.  
  37. // sort by length
  38.  
  39.   L.sort(cmp_length);
  40.   L.print("sorted by length:\n");
  41.   newline;
  42.   newline;
  43.  
  44.  
  45.  
  46. // bucket_sort by first character
  47.  
  48.   L.bucket_sort(0,255,F);
  49.   L.print("sorted by s[0]:\n");
  50.   newline;
  51.   newline;
  52.  
  53. }
  54.