Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program bubblesort;
- uses crt, DOS;
- const N=50000;
- type
- tab1 = array [1..N] of integer;
- var
- t1,t2,t3 : tab1;
- hour,minute,second,sec100,hour1,minute1,second1,sec1001 : Word;
- procedure Fill();
- var
- i : integer;
- begin
- randomize;
- for i:=1 to N do t1[i]:=random(75000);
- end;
- procedure Copy();
- var
- i : integer;
- begin
- for i:=1 to N do
- begin
- t2[i]:=t1[i];
- t3[i]:=t1[i];
- end;
- end;
- procedure Print(t1 : tab1);
- var
- i : integer;
- begin
- for i:=1 to N do write(t1[i]:3,'|');
- writeln;
- end;
- procedure Czas();
- begin
- write('Czas wykonania sortowania: ');
- write(sec1001+second1*100+minute1*6000+hour*360000-hour*360000-minute*6000-second*100-sec100);
- writeln(' setnych sekundy');
- end;
- procedure Sort(); //zwykle
- var
- i,j,x : integer;
- licznik : integer=0;
- begin
- gettime(hour,minute,second,sec100);
- for j:=1 to N-1 do
- for i:=1 to N-1 do
- if t1[i]>t1[i+1] then
- begin
- x:=t1[i]; t1[i]:=t1[i+1]; t1[i+1]:=x;
- //Print(t1);
- //licznik+=1;
- end;
- gettime(hour1,minute1,second1,sec1001);
- Czas();
- //writeln('Posorotwano w ',licznik,' operacjach');
- end;
- procedure Sort_2(); //jednostronne pominięcie pustych operacji
- var
- i,j,x,licznik,p: integer;
- begin
- licznik:=0;
- j:=N-1;
- gettime(hour,minute,second,sec100);
- repeat
- for i:=1 to j do
- if t2[i]>t2[i+1] then
- begin
- x:=t2[i]; t2[i]:=t2[i+1]; t2[i+1]:=x;
- p:=1;
- //Print(t2);
- //licznik+=1;
- end;
- if p=0 then j:=0
- else dec(j);
- until j<1;
- gettime(hour1,minute1,second1,sec1001);
- Czas();
- //writeln('Posorotwano w ',licznik,' operacjach');
- end;
- procedure Sort_3(); //dwustronne pominięcie pustych operacji
- var
- i,j,x,licznik,p,pmin,pmax: integer;
- begin
- licznik:=0;
- pmin:=1;
- pmax:=N-1;
- gettime(hour,minute,second,sec100);
- repeat
- p:=0;
- for i:=pmin to pmax do
- if t3[i]>t3[i+1] then
- begin
- x:=t3[i]; t3[i]:=t3[i+1]; t3[i+1]:=x;
- if p=0 then pmin:=i;
- p:=i;
- //Print(t2);
- //licznik+=1;
- end;
- if pmin>1 then dec(pmin);
- pmax:=p-1;
- until p=0;
- gettime(hour1,minute1,second1,sec1001);
- Czas();
- //writeln('Posorotwano w ',licznik,' operacjach');
- end;
- begin
- Fill();
- Copy();
- //Print(t1);
- readln;
- Sort();
- //readln;
- Sort_2();
- //readln;
- Sort_3();
- readln;
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment