program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils,windows;
type
wsk= ^a;
a = record
k: longint;
w: wsk;
end;
procedure lista;
var tab: array[1..1000000] of boolean;
n,i,l,x,z,c: longint;
pierw,poprz,q,head:wsk;
t1,t2,t3,t4,t5: extended;
t1a,t1b,t2a,t2b,t3a,t3b,t4a,t4b,t5a,t5b,freq:Int64;
begin
if QueryPerformanceFrequency(Freq) then
QueryPerformanceCounter(t1a);
randomize;
readln(n);
pierw:=nil; //1)tworzenie
for i:= 1 to 1000000 do
tab[i]:=true;
for l:=1 to n do
begin
repeat
x:=random(100000)+1;
until tab[x]=true;
// write(x,' ' );
tab[x]:=false;
new(q);
q^.k:=x;
poprz:=pierw;
if (pierw=nil) or (pierw^.k>q^.k) then
begin
q^.w:=pierw;
pierw:=q;
end
else begin
while (poprz^.w<>nil) and (poprz^.w^.k<q^.k) do
begin
poprz:=poprz^.w;
end;
q^.w:=poprz^.w;
poprz^.w:=q;
end;
end;
QueryPerformanceCounter(t1b);
t1:=(t1b-t1a)/Freq*1000;;
Writeln('czas tworzenia ',t1,' ');
if QueryPerformanceFrequency(Freq) then
QueryPerformanceCounter(t2a);
z:=n div 10;
for c:=1 to z do //2)dodawanie wylosowanych elementów
begin
x:= random(1000000)+1;
//writeln(x,' wylosowany ');
new(q);
q^.k:=x;
poprz:=pierw;
if (pierw=nil) or (pierw^.k>q^.k) then
begin
q^.w:=pierw;
pierw:=q;
end
else begin
while (poprz^.w<>nil) and (poprz^.w^.k<q^.k) do
begin
poprz:=poprz^.w;
end;
q^.w:=poprz^.w;
poprz^.w:=q;
end;
end;
// writeln;
{head:=pierw;
while head<>nil do
begin
write(head.k,' ');
head:=head.w;
end;}
QueryPerformanceCounter(t2b);
t2:=(t2b-t2a)/Freq*1000;;
Writeln('czas dodawania losowych elementów ',t2,' ');
if QueryPerformanceFrequency(Freq) then
QueryPerformanceCounter(t3a);
head:=pierw;
z:=n div 10;
for c:=1 to z do //3)wyszukiwanie wylosowanych elementów
begin
x:= random(1000000)+1;
while (head.k=x) or (head=nil) do
head:=head.w;
end;
QueryPerformanceCounter(t3b);
t3:=(t3b-t3a)/Freq*1000;;
Writeln('czas wyszukiwania ',t3,' ');
if QueryPerformanceFrequency(Freq) then
QueryPerformanceCounter(t4a);
for c:=1 to n do //4)usuwanie
begin
head:=pierw;
x:=random(1000000)+1;
//write('usun',x);
while (head.k=x) or (head=nil) do
begin
poprz:=head;
head:=head.w;
end;
if head.k=x then
begin
poprz.w:=head.w;
dispose(head);
end;
end;
{ writeln('after');
head:=pierw;
while head<>nil do
begin
write(head.k,' ');
head:=head.w;
end;}
QueryPerformanceCounter(t4b);
t4:=(t4b-t4a)/Freq*1000;;
Writeln('czas usuwania ',t4,' ');
if QueryPerformanceFrequency(Freq) then
QueryPerformanceCounter(t5a);
head:=pierw;
while head<>nil do
begin
head.k:=head.k+1;
head:=head.w;
end;
QueryPerformanceCounter(t5b);
t5:=(t5b-t5a)/Freq*1000;;
Writeln('czas przegladania ',t5,' ');
{ writeln('ending');
head:=pierw;
while head<>nil do
begin
write(head.k,' ');
head:=head.w;
end;}
end;
// procedure przegladanie;
begin
lista;
{ TODO -oUser -cConsole Main : Insert code here }
readln;
end.