Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,41 @@
|
|||
MODULE Counting EXPORTS Main;
|
||||
|
||||
IMPORT IO, Fmt;
|
||||
|
||||
VAR test := ARRAY [1..8] OF INTEGER {80, 10, 40, 60, 50, 30, 20, 70};
|
||||
|
||||
PROCEDURE Sort(VAR a: ARRAY OF INTEGER; min, max: INTEGER) =
|
||||
VAR range := max - min + 1;
|
||||
count := NEW(REF ARRAY OF INTEGER, range);
|
||||
z := 0;
|
||||
BEGIN
|
||||
FOR i := FIRST(count^) TO LAST(count^) DO
|
||||
count[i] := 0;
|
||||
END;
|
||||
|
||||
FOR i := FIRST(a) TO LAST(a) DO
|
||||
INC(count[a[i] - min]);
|
||||
END;
|
||||
|
||||
FOR i := min TO max DO
|
||||
WHILE (count[i - min] > 0) DO
|
||||
a[z] := i;
|
||||
INC(z);
|
||||
DEC(count[i - min]);
|
||||
END;
|
||||
END;
|
||||
END Sort;
|
||||
|
||||
BEGIN
|
||||
IO.Put("Unsorted: ");
|
||||
FOR i := FIRST(test) TO LAST(test) DO
|
||||
IO.Put(Fmt.Int(test[i]) & " ");
|
||||
END;
|
||||
IO.Put("\n");
|
||||
Sort(test, 10, 80);
|
||||
IO.Put("Sorted: ");
|
||||
FOR i := FIRST(test) TO LAST(test) DO
|
||||
IO.Put(Fmt.Int(test[i]) & " ");
|
||||
END;
|
||||
IO.Put("\n");
|
||||
END Counting.
|
||||
Loading…
Add table
Add a link
Reference in a new issue