DataMuseum.dk

Presents historical artifacts from the history of:

CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦744a53a96⟧ TextFile

    Length: 1792 (0x700)
    Types: TextFile
    Names: »BININSRT.PAS«

Derivation

└─⟦092727b26⟧ Bits:30005927 Demoprogrammer til Pascal bog (Jet-80)
    └─ ⟦this⟧ »BININSRT.PAS« 
└─⟦3702e543b⟧ Bits:30003064 Demoprogrammer A-J til Pascal bog
    └─ ⟦this⟧ »BININSRT.PAS« 
└─⟦f983c2ef3⟧ Bits:30004681 Pascal opgaver (Butler)
    └─ ⟦this⟧ »BININSRT.PAS« 

TextFile

        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»