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

  1. #include <LEDA/sortseq.h>
  2.  
  3. declare2(sortseq,string,int);
  4.  
  5. void print(sortseq(string,int) S)
  6. { seq_item it;
  7.   forall_seq_items(it,S) cout << S.key(it) << "\n";
  8.   newline;
  9.   S.clear();
  10. }
  11.  
  12.  
  13. main()
  14. {
  15.   sortseq(string,int) S,S1,S2;
  16.  
  17.   string f_name = read_string("file name: ");
  18.  
  19.   file_istream input(f_name);
  20.  
  21.   string s;
  22.  
  23.   while (input >> s)  S.insert(s,0);
  24.  
  25.   cout << S.size() << " strings.\n\n";
  26.  
  27.  
  28.   print(S);
  29.  
  30.   string s1,s2;
  31.  
  32.   do { s1 = read_string("s1 = ");
  33.  
  34. /*
  35.        s2 = read_string("s2 = ");
  36.  
  37.        if (s1 > s2) 
  38.         { cerr << "illegal input: s1 > s2.\n";
  39.           continue;
  40.          }
  41. */
  42.  
  43.        seq_item it1 = S.locate(s1);
  44.  
  45.        cout << "SPLIT at " << S.key(it1) << "\n";
  46.        newline;
  47.  
  48. /*
  49.        seq_item it2 = S.locate(s2);
  50.      
  51.        while (it1!=it2)
  52.          { cout << S.key(it1) << "\n"; 
  53.            it1 = S.succ(it1);
  54.           }
  55. */
  56.  
  57.        S.split(it1,S1,S2);  //now S is mepty
  58.  
  59.        print(S1);
  60.  
  61.        print(S2);
  62.  
  63.        S1.conc(S2);         //now S2 is empty
  64.  
  65.        S.conc(S1);          //now S1 is empty
  66.  
  67.  
  68.      } while (s1 != "");
  69.     
  70. }
  71.