QuickSort.borg

QuickSort.borg


{ QuickSort(V,Low,High):
   { Left: Low;
     Right: High;
     Pivot: V[(Left + Right) // 2];
     Save: 0;
     until(Left > Right,
           { while(V[Left] < Pivot, Left:= Left+1);
             while(V[Right] > Pivot, Right:= Right-1);
             if(Left <= Right,
                { Save:= V[Left];
                  V[Left]:= V[Right];
                  V[Right]:= Save;
                  Left:= Left+1;
                  Right:= Right-1 }) });
     if(Low < Right, QuickSort(V, Low, Right));
     if(High > Left, QuickSort(V, Left, High)) };
     display("initialised table",eoln);
     V[20000]: random();
     t: clock();
     display("sorting table",eoln);
     QuickSort(V,1,size(V));
     display("done: time = ",clock()-t) }