Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,54 @@
MODULE Bubble;
IMPORT Out;
TYPE
TItem = INTEGER;
VAR
I:LONGINT;
A:ARRAY 10 OF TItem;
PROCEDURE Init(VAR A:ARRAY OF TItem);
BEGIN
A[0] := 1; A[1] := 10; A[2] := 2; A[3] := 5;
A[4] := -1; A[5] := 5; A[6] := -19; A[7] := 4;
A[8] := 23; A[9] := 0;
END Init;
PROCEDURE Swap(VAR A,B:TItem);
VAR
Temp:TItem;
BEGIN
Temp := A;
A := B;
B := Temp;
END Swap;
PROCEDURE BubbleSort(VAR A:ARRAY OF TItem);
VAR
N,Newn,I:LONGINT;
BEGIN
N := LEN(A)-1;
REPEAT
Newn := 0;
FOR I := 1 TO N DO
IF A[I-1] > A[I] THEN
Swap(A[I-1], A[I]);
Newn := I;
END;
END;
N := Newn;
UNTIL N = 0;
END BubbleSort;
BEGIN
Init(A);
Out.String("Before sorting: "); Out.Ln;
FOR I := 0 TO LEN(A)-1 DO Out.Int(A[I],0); Out.Char(' '); END;
Out.Ln;
BubbleSort(A);
Out.String("After sorting: "); Out.Ln;
FOR I := 0 TO LEN(A)-1 DO Out.Int(A[I],0); Out.Char(' '); END;
Out.Ln;
END Bubble.