Annotation of 43BSDTahoe/ucb/pascal/tstpx/src/quicksort.p, revision 1.1.1.1

1.1       root        1: program quicksort(output);
                      2:   const n = 100;
                      3:   var i,z: integer;
                      4:       a: array[1..n] of integer;
                      5: 
                      6:   procedure sort(l,r: integer);
                      7:     var i,j,x,w: integer;
                      8:   begin {quicksort with recursion on both partitions}
                      9:     i := l; j := r; x := a[(i+j) div 2];
                     10:     repeat
                     11:       while a[i] < x do i := i+1;
                     12:       while x < a[j] do j := j-1;
                     13:       if i <= j then
                     14:         begin w := a[i]; a[i] := a[j]; a[j] := w;
                     15:           i := i+1; j := j-1
                     16:         end
                     17:     until i > j;
                     18:     if l < j then sort(l,j);
                     19:     if l < r then sort(i,r);
                     20:   end { sort } ;
                     21: 
                     22: begin z := 1729;  {generate random sequence}
                     23:   for i := 1 to n do
                     24:     a[i] := round(1000 * random(1.0));
                     25:   writeln(wallclock);
                     26:   sort(1,n);
                     27:   writeln(wallclock);
                     28:   for i := 1 to n-1 do
                     29:    if a[i] > a[i+1] then writeln(i,a[i],a[i+1]);
                     30: end .

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.