1
\$\begingroup\$

I would prefer a review of:

  • Efficiency
  • Standards
  • Different approaches

Here's the code:

program bubbleSort;
var
        toSort: array[1..5] of integer = (3, 25, 2, 69, 1);
        passChanges: boolean = true;
        counter, index, temp: integer;
begin
        while passChanges do
        begin
                index := 1;

                passChanges := false;

                for index := 1 to length(toSort) - 1  do
                begin
                        if (toSort[index] > toSort[index +1]) then
                        Begin
                                temp := toSort[index + 1];
                                toSort[index + 1] := toSort[index];
                                toSort[index] := temp;
                                passChanges := true;
                        end;
                end;
        end;

        for counter := 1 to length(toSort) do
                writeln(toSort[counter]);

        readln;
end.
\$\endgroup\$
  • \$\begingroup\$ Can someone fix the formatting for me? For some reason it won't work. \$\endgroup\$ – Hassan Althaf Mar 20 '17 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.