|
|
back to boardwhy crash? Posted by zealot 17 Nov 2002 12:44 my program here: program tree_bianli; const max=30000; type arr0=record data:longint; lchild,rchild:longint; end; var t:array[0..max] of arr0; i,n,num:longint; w:array[0..max] of longint; f:array[0..60000] of longint; procedure readdata; var i,j,y:longint; begin readln(n); for i:=1 to n do begin read(t[i].data); f[t[i].data]:=i; end; end; procedure find(f,r,m:longint); var i:longint; begin i:=f; while t[i].data<t[m].data do inc(i); dec(i); if i>=f then t[m].lchild:=t[i].data; if r-1>=i then t[m].rchild:=t[r].data; if i>f then find(f,i-1,i); if r-1>i then find(i+1,r-1,r); end; procedure print(p:longint); begin if t[p].rchild<>0 then print(f[t[p].rchild]); if t[p].lchild<>0 then print(f[t[p].lchild]); inc(num);w[num]:=t[p].data; end; BEGIN readdata; find(1,n-1,n); print(n); for i:=1 to num-1 do write(w[i],' ');writeln(w[num]); END. Re: why crash? I think you go out of the array somewhere. Check it with N=30000. |
|
|