home *** CD-ROM | disk | FTP | other *** search
- program ZipSort; { Version 1.1 }
-
- {
- the sort procedure is a Turbo Pascal version of
- a basic program released by Mentat Software (c)
- R. F. Ashwell III 1830 Dover Rd, Dover Fl 33527
-
- - ZipSort - written by
- Jim Savold AT&T PC 6300
- 2137 Cherrywood Circle
- Naperville, Il 60565
-
- the sort is very fast - change the maxrec const
- to 1000 or more and time the result ( < 5 sec )
- - - - - - - - - - - - - - - - - - - - - - - - -
- modified Jan 16 to permit sorting on all or any
- part of a string - the change has increased the
- sort time slightly. ( 1000 records 5 to 7 sec )
- please send comments/improvements to Jim Savold
- - - - - - - - - - - - - - - - - - - - - - - - -
- }
-
- const
- len = 11; { length of sort record + 1 }
- maxrec = 1000; { set as required }
-
- type
- string_data = string [ 10 ]; { length of record }
-
- var
- sort_data : array [ 1..maxrec ] of string_data;
- hold,pass : array [ 1..maxrec ] of integer;
- part,indx,count,total : integer;
-
- procedure switch ( var a , b : integer );
- var
- temp : string_data;
-
- begin
- temp := sort_data [ a ];
- sort_data [ a ] := sort_data [ b ];
- sort_data [ b ] := temp;
- end; { of switch procedure }
-
- procedure sort;
- label 10,20,30,40,50,60,70,80;
-
- var
- areg,breg,creg,dreg,ereg,freg,xreg : integer;
-
- begin
- areg := total; breg := 0; creg := 0; dreg := 1; ereg := 1; freg := 0;
- 10 : if ( areg - ereg ) < 9 then goto 70;
- breg := ereg;
- creg := areg;
- 20 : if ( copy ( sort_data [ breg ] , part , len - part ) ) >
- ( copy ( sort_data [ creg ] , part , len - part ) ) then begin
- switch ( creg , breg );
- goto 60;
- end;
- 30 : creg := creg - 1;
- if creg > breg then goto 20;
- creg := creg + 1;
- 40 : dreg := dreg + 1;
- if ( breg - ereg ) < ( areg - creg ) then begin
- hold [ dreg ] := creg;
- pass [ dreg ] := areg;
- areg := breg;
- goto 10;
- end;
- hold [ dreg ] := ereg;
- pass [ dreg ] := breg;
- ereg := creg;
- goto 10;
- 50 : if ( copy ( sort_data [ creg ] , part , len - part ) ) <
- ( copy ( sort_data [ breg ] , part , len - part ) ) then begin
- switch ( creg , breg );
- goto 30;
- end;
- 60 : breg := breg + 1;
- if creg > breg then goto 50;
- creg := creg + 1;
- goto 40;
- 70 : if ( areg - ereg + 1 ) = 1 then goto 80;
- for breg := ( ereg + 1 ) to areg do begin
- for creg := ereg to ( breg - 1 ) do begin
- freg := breg - creg + ereg - 1;
- if ( copy ( sort_data [ freg ] , part , len - part ) ) >
- ( copy ( sort_data [ freg + 1 ] , part , len - part ) ) then begin
- xreg := freg + 1;
- switch ( freg , xreg );
- end;
- end;
- end;
- 80 : ereg := hold [ dreg ];
- areg := pass [ dreg ];
- dreg := dreg - 1;
- if dreg = 0 then exit;
- goto 10;
- end; { of sort procedure }
-
- procedure make_string;
- var
- ch : string_data;
- make : integer;
-
- begin
- randomize; ch := '';
- for indx := 1 to total do begin
- gotoxy(1,12); write( 'building sort string ' , indx:4 , ' of ', total );
- for make := 1 to 10 do begin
- ch := ch + chr( random ( 27 ) + 64 );
- end;
- sort_data [ indx ] := ch;
- ch := '';
- end;
- end; { of procedure to make a 'total' number of 10 random character strings }
-
- begin { demonstration of ZipSort }
- clrscr;
- gotoxy( 1 , 2 );
- writeln( 'ZipSort Demonstration' );
- writeln;
- writeln( 'Enter the number of records to build and sort ( 1 - 1000 ) ',^g );
- readln ( total );
- writeln;
- writeln( 'Enter the position in the record to sort ( 1 - 10 ) ',^g );
- readln ( part );
- make_string;
- writeln;
- writeln( '*** SORT START ***',^g );
- sort;
- writeln( '*** SORT ENDED ***',^g );
- writeln;
- writeln( 'sorted string list' );
- count := 0;
- for indx := 1 to total do begin { to display sorted strings }
- count := count + 1;
- if count = 8 then begin
- writeln;
- count := 1;
- end;
- write( ' ',sort_data [ indx ] );
- end;
- end. { of demonstration program }