|
|
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: 1792 (0x700)
Types: TextFile
Names: »BININSRT.PAS«
└─⟦092727b26⟧ Bits:30005927 Demoprogrammer til Pascal bog (Jet-80)
└─⟦this⟧ »BININSRT.PAS«
└─⟦3702e543b⟧ Bits:30003064 Demoprogrammer A-J til Pascal bog
└─⟦this⟧ »BININSRT.PAS«
PROGRAM bininsrt;
CONST
antal = 1000;
max = 500;
TYPE
tabeltype = ARRAY(.1 .. antal.) OF INTEGER;
VAR
i, n : INTEGER;
tabel : tabeltype;
PROCEDURE sorter(venstre, hoejre : INTEGER;
VAR vektor : tabeltype);
VAR
naeste, i, j, midt, v, h : INTEGER;
BEGIN
FOR i:= venstre + 1 TO hoejre DO
BEGIN
naeste := vektor(.i.); (* naeste skal på plads *)
v := venstre;
h := i - 1;
WHILE v <= h DO
BEGIN
midt := (v + h) DIV 2;
IF naeste < vektor(.midt.)
THEN h := midt - 1
ELSE v := midt + 1;
END; (* WHILE *)
FOR j := i - 1 DOWNTO v DO
vektor(.j + 1.) := vektor(.j.);
vektor(.v.) := naeste;
END; (* FOR i *)
END;
BEGIN (* bininsrt *)
WRITE(CHR(12), 'Tast antal (max 1000): '); READLN(n);
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;
sorter(1, n, tabel);
WRITELN('Her er tallene sorteret:');
FOR i := 1 TO n DO
WRITE(tabel(.i.) : 5);
WRITELN;
END. (* bininsrt *)
«eof»