program bubblesort;

uses crt,dos;

const n=5000;

var a:array[1..n] of word;

h,st1,mi1,se1,hu1,st2,mi2,se2,hu2:word;

i,j,k,vgl,vert:longint;

dauer,zeit1,zeit2:real;

begin

clrscr;

vgl:=0;

vert:=0;

randomize;

for i:=1 to n do a[i]:=random(n);

writeln('Bubblesort von ',n,' Elementen');

gettime(st1,mi1,se1,hu1);

writeln('Startzeit: ',st1,':',mi1,':',se1,':',hu1);

for i:=1 to n-1 do

for j:=i+1 to n do begin

inc(vgl);

if a[i]>a[j] then begin

h:=a[i];

a[i]:=a[j];

a[j]:=h;

inc(vert);

end;

end;

gettime(st2,mi2,se2,hu2);

writeln(' Endzeit: ',st2,':',mi2,':',se2,':',hu2);

zeit1:=st1*3600+mi1*60+se1+hu1/100;

zeit2:=st2*3600+mi2*60+se2+hu2/100;

dauer:=zeit2-zeit1;

writeln('Dauer des Sortiervorganges: ',dauer:5:2,' Sekunden');

writeln('Anzahl der Vertauschungen: ',vert,' Vergleiche: ',vgl);

readln;

for k:=1 to n do

write(a[k],' ');

writeln;

repeat until keypressed;

end.