Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(Added Oberon-02)
Line 4,372: Line 4,372:
{{out}}
{{out}}
<pre>@[-31, 0, 2, 2, 4, 65, 83, 99, 782]</pre>
<pre>@[-31, 0, 2, 2, 4, 65, 83, 99, 782]</pre>

=={{header|Oberon-2}}==
<syntaxhighlight lang="oberon2">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.
</syntaxhighlight>


=={{header|Objeck}}==
=={{header|Objeck}}==