You are here:

# Pascal/sorting within arrays

Advertisement

vitronix wrote at 2012-11-27 09:28:43
Program BubbleSortDemo;

{ Program that sorts an array using the bubblesort algorithm }

var

Sort : array [1..10] of integer;

Pass : integer;

procedure FillArray;

var

i : integer;

begin

Randomize;

WriteLn ('Unsorted nubers :');

for i := 1 to 10 do

begin

Sort [i] := Random (10);

Write (Sort [i],' ');

end;

writeln;

end;

procedure PrintPass;

var

i : integer;

begin

write ('Pass : ', Pass);

for i := 1 to 10 do

write (Sort [i]);

writeln;

end;

procedure BubbleSort;

var

Sorted : boolean;

temp   : integer;

i      : integer;

begin

Pass := 0;

repeat

inc (Pass);

Sorted := TRUE;

for i := 1 to 9 do

begin

if (Sort [i] > Sort [i+1]) then

begin

temp := Sort[i];

Sort [i] := Sort [i+1];

Sort [i+1] := temp;

Sorted := FALSE;

end;

end;

if not (Sorted) then PrintPass;

until Sorted;

end;

begin

FillArray;

BubbleSort;

end.

Pascal

All Answers

Ask Experts

Volunteer

#### Mohammed

##### Expertise

Simply put, I`ve used pascal for many years now. I`m assiting professors at the American University In Cairo regarding pascal.

©2017 About.com. All rights reserved.

Browse Answers: