|
|
DataMuseum.dkPresents historical artifacts from the history of: CP/M |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about CP/M Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 2048 (0x800)
Types: TextFile
Names: »QUICKSOR.PAS«
└─⟦08ea08c61⟧ Bits:30003924 PolyPascal programmer
└─⟦this⟧ »QUICKSOR.PAS«
PROGRAM quicksor;
CONST
antal = 1000;
TYPE
tabeltype = ARRAY(.1 .. antal.) OF INTEGER;
VAR
n, max, i : INTEGER;
tabel : tabeltype;
PROCEDURE sorter(venstre, hoejre: INTEGER; VAR vektor : tabeltype);
VAR
v, h, midt, byt : INTEGER;
BEGIN (* sorter *)
v := venstre;
h := hoejre;
midt := vektor(.(v + h) DIV 2.);
REPEAT
WHILE vektor(.v.) < midt DO
v := v + 1;
WHILE midt < vektor(.h.) DO
h := h - 1;
IF v <= h
THEN
BEGIN
byt := vektor(.v.);
vektor(.v.) := vektor(.h.);
vektor(.h.) := byt;
v := v + 1;
h := h - 1;
END;
UNTIL v > h;
IF venstre < h
THEN sorter(venstre, h, vektor);
IF v < hoejre
THEN sorter(v, hoejre, vektor);
END; (* sorter *)
BEGIN (* quicksor *)
WRITE(CLRHOM);
WRITELN('Programmet finder n tilfældige hele tal fra 1',
' til max og sorterer dem.');
WRITELN;
WRITE('Tast antallet n (højst ', antal, ' ): '); READLN(n);
WRITE('Tast den øvre grænse max: '); READLN(max);
WRITELN;
WRITELN('Følgende tal vil blive sorteret:');
FOR i := 1 TO n DO
BEGIN
tabel(.i.) := RANDOM(max) + 1;
WRITE(tabel(.i.) : 5);
END;
WRITELN;
WRITELN;
sorter(1, n, tabel);
WRITELN('Her er tallene sorteret:');
WRITELN;
FOR i := 1 TO n DO
WRITE(tabel(.i.) : 5);
WRITELN;
END. (* quicksor *)
«eof»