home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / plisampl.zip / SORT < prev    next >
Text File  |  1987-09-30  |  2KB  |  80 lines

  1. CLRSCR;
  2. PRINT(SYSPRINT,REPEAT(' ',36),'Sort');
  3. PUTCRLF;
  4. PUTCRLF;
  5. PUTCRLF;
  6. PRINT(SYSPRINT,'Input file descriptor? ');
  7. input_file_descriptor=GETSTRING;
  8. infile=OPEN(input_file_descriptor,'r');
  9. infile_eof=FALSE;
  10. num_lines=0;
  11. DO WHILE(! infile_eof);
  12.   tem_string=GETSTRING(infile);
  13.   IF ENDFILE(infile) THEN
  14.     infile_eof=TRUE;
  15.   ELSE
  16.     DO;
  17.       num_lines=num_lines+1;
  18.       line(num_lines)=tem_string;
  19.     END;
  20. END;
  21. PRINT(SYSPRINT,'Output file descriptor? ');
  22. output_file_descriptor=GETSTRING;
  23. outfile=OPEN(output_file_descriptor,'w');
  24. IF num_lines > 0 THEN
  25.   DO;
  26.     left=num_lines/2;
  27.     left=left+1;
  28.     right=num_lines;
  29.     tem_string=line(1);
  30.     finished=FALSE;
  31.     DO WHILE(right > 1);
  32.       IF left > 1 THEN
  33.         DO;
  34.           left=left-1;
  35.           tem_string=line(left);
  36.         END;
  37.       ELSE
  38.         DO;
  39.           tem_string=line(right);
  40.           line(right)=line(1);
  41.           right=right-1;
  42.         END;
  43.       IF right > 1 THEN
  44.         DO;
  45.           key_index_2=left;
  46.           finished=FALSE;
  47.           DO WHILE(! finished);
  48.             key_index_1=key_index_2;
  49.             key_index_2=2*key_index_2;
  50.             IF key_index_2 > right THEN
  51.               finished=TRUE;
  52.             ELSE
  53.               DO;
  54.                 IF key_index_2 != right THEN
  55.                   DO;
  56.                     IF UPPER(line(key_index_2))
  57.                      < UPPER(line(key_index_2+1)) THEN
  58.                       key_index_2=key_index_2+1;
  59.                   END;
  60.                 IF UPPER(tem_string) >= UPPER(line(key_index_2)) THEN
  61.                   finished=TRUE;
  62.                 ELSE
  63.                   DO;
  64.                     line(key_index_1)=line(key_index_2);
  65.                   END;
  66.               END;
  67.           END;
  68.           line(key_index_1)=tem_string;
  69.         END;
  70.     END;
  71.     line(1)=tem_string;
  72.     line_num=1;
  73.     DO WHILE(line_num <= num_lines);
  74.       PRINT(outfile,line(line_num));
  75.       PUTCRLF(outfile);
  76.       line_num=line_num+1;
  77.     END;
  78.   END;
  79. CLOSE(outfile);
  80.