uses Graph;

type IntArr = array[1..100] of integer;

const 
 h = 20;
 dist = 10;
 cellsize = 30;

procedure DrawElemAsHystogram(const a: IntArr; n,i: integer; x,y: integer);
begin
 Rectangle(x+(i-1)*(h+dist),y,x+(i-1)*(h+dist)+h,y-a[i]);
end;

procedure DrawArrayAsHystogram(const a: IntArr; n: integer; x,y: integer);
begin
 for var i := 1 to n do
 DrawElemAsHystogram(a,n,i,x,y);
end;

procedure DrawArr(const a: IntArr; n: integer);
begin
 Window.Clear;
 DrawArrayAsHystogram(a,n,10,340); 
 Sleep(100);
end;

procedure BubbleSort(var a: IntArr; n: integer);
begin
 for var i:=n downto 2 do
 for var j:=1 to i-1 do
 if a[j+1] < a[j] then
 begin
 Swap(a[j+1],a[j]);
 DrawArr(a,n);
 end;
end;

var 
 a: IntArr;
 n: integer := 20;

begin
 Window.Title := 'Пузырьковая сортировка';
 Window.SetSize(640,380);
 for var i := 1 to n do
 a[i] := Random(10,299);
 
 Brush.Color := Color.LightGreen;
 DrawArrayAsHystogram(a,n,100,340); 
 BubbleSort(a,n);
end.

Оценка - 1.0 (5)

 Похожие публикации
2016-01-14 • Просмотров [ 1835 ]