witam na foum! [soczek]

pisze do Was - Specjalistow - z moim problemem:

napisalem program ktory nie chce dzialac tak jak powinien - nie losuje tylko wypisuje kolejno krawedzie.

temat to:
[i]Algorytm generowania grafu G = G(n, k) w tablicy E, procedura przepisania informacji do tablicy S, drukowanie z E i drukowanie z S, pomiar złożoności. [/i]

a to co napisalem:

[code]program projekt(input,output);
uses dos;
const nmax=100; kmax=nmax*(nmax-1) div 2;
type ind=1..nmax; ind1=1..kmax;
elem=1..nmax;
zbior=set of elem;
r=record a,b:integer; code:Boolean; end;
rs=record w:zbior; l:integer; end;
t=array[ind] of integer;
t1=array[ind1] of r; { E }
ts=array[ind] of rs; { S }
alfa=string[15];

var E:t1; S:ts; n,rep,i,k,total,c:integer;
key:integer; wariant:integer; czas1, czas2:extended;
out:text; dev:alfa;

procedure czyt1(var n,k,rep:integer);
begin
write('n, k, rep ='); read(n, k, rep);
end; { czyt1 }

procedure init(n:integer; var E:t1; var total:integer);
var i,j,h:integer;
begin
h:=0;
for i:=1 to n - 1 do
for j:=i + 1 to n do
begin
h:=h + 1;
with E[h] do begin a:=i; b:=j end;
end;
total:=h;
end; { init }

procedure Gnk(n,k,total:integer; var E:t1);
var i,l,z:integer; x:r;
begin
l:=total;
for i:=1 to k do
begin
z:=random(l) + 1;
x:=E[z]; E[z]:=E[l]; E[l]:=x;
l:=l - 1;
end;
end; { Gnk }

procedure transES(n,total:integer; var E:t1; var S:ts);
var i,h:integer;
begin
for i:=1 to n do with S[i] do begin w:=[]; l:=0; end;
for h:=1 to total do
with E[h] do

``````    begin
with S[a] do begin w:=w + [b]; l:=l + 1; end;
with S[b] do begin w:=w + [a]; l:=l + 1; end;
end;
``````

end; { transES }

procedure druk1(n,k,rep:integer);
begin
writeln(out);
writeln(out, 'Gnk, n =', n:3, ', k =', k:4, ', rep =', rep:5);
end; { druk1a }

procedure drukE(n,total:integer; var E:t1);
var i,h,l:integer;
begin
write(out, 'Edges from E:');
h:=0;
for l:=1 to total do
with E[l] do
if code then
begin
h:=h + 1; write(out, a:4, b:3);
if h mod 10 = 0 then writeln(out)
end;
writeln(out);
end; { drukE }

procedure drukS(n:integer; var S:ts);
var i,j,h:integer;
begin
write(out, 'Edges from S:');
h:=0; { licznik krawedzi }
for i:=1 to n - 1 do
with S[i] do
for j:=i + 1 to n do
if j in w then
begin
write(out, i:4, j:3); h:=h + 1;
if h mod 10 = 0 then writeln(out)
end;
writeln(out); writeln(out);
end; { drukS }

procedure GnkE(n,k, total:integer; var E:t1);
var h:integer;
begin
for h:=1 to total do E[h].code:= random <= k;
end; { GnpE }

procedure drukzbior(first:integer; z:zbior);
var x:elem;
begin
x:=first;
while z <> [] do
begin
if x in z then
begin write(out, x:3, ','); z:=z - [x] end;
x:=x + 1;
end;
end; { drukzbior}

procedure drukS1(n:integer; var S:ts);
var i,j,h:integer;
begin
writeln(out, 'Tablica S:');
for i:=1 to n do
begin
write(out, i:3, ':');
with S[i] do drukzbior(1, w);
writeln(out);
end;
writeln(out);
end; { drukS1 }

function pomiar:extended;
var h,m,s,s100:word;
begin
gettime(h, m, s, s100);
pomiar := h * 3600 + m * 60 + s + (s100 / 100);
end; { pomiar }

begin
assign(out, dev); rewrite(out);
randomize;
repeat
begin { Gnk w E, transES }
czyt1

``````      (n, k, rep);
czas1:=pomiar;
druk1(n, k, rep);
init(n, E, total);
for i:=1 to rep do
begin
GnkE(n, total, k, E);
drukE(n, total, E);
transES(n, total, E, S);
drukS(n, S);
drukS1(n, S);
end;
end;
czas2 := pomiar;
writeln('czas:',(czas2-czas1):6:2,' [s]');
``````