Sorting algorithms/Bogosort: Difference between revisions

Content added Content deleted
Line 388: Line 388:
RETURN TRUE;
RETURN TRUE;
END Sorted;
END Sorted;

PROCEDURE PrintArray(VAR a: ARRAY OF INTEGER);
VAR i: INTEGER;
BEGIN
FOR i := 0 TO LEN(a) - 1 DO
Out.Int(a[i], 0);
Out.String(" ");
END;
END PrintArray;


PROCEDURE Shuffle*(VAR a: ARRAY OF INTEGER);
PROCEDURE Shuffle*(VAR a: ARRAY OF INTEGER);
Line 415: Line 406:
Shuffle(a);
Shuffle(a);
END;
END;
FOR i := 0 TO LEN(a) - 1 DO
PrintArray(a);
Out.Int(a[i], 0);
Out.String(" ");
END;
Out.Ln;
Out.Ln;
END Bogo.</pre>
END Bogo.</pre>


Init initializes the array as 1..10, then it is shuffled, and then the while loop continually shuffles until Sorted returns true.
Init initializes the array as 1 thru 10, then it is shuffled, and then the while loop continually shuffles until Sorted returns true.


=={{header|OCaml}}==
=={{header|OCaml}}==