Witam, mam problem ze wskaznikami, dokładniej z sortowaniem, wyskakuje "invalid pointer operation" jest to dziwne bo czasem działa a czasem nie i nie mam pojęcia czemu tak jest.
Błąd pojawia sie w procedurze sortuj tutaj:
while tmp <> nil do begin
i := i + 1;
tmp.liczba := tab[i];
tmp := tmp.nast;
end;
Oto cały kod tej procedury:
type
wsk = ^rec;
rec = record
liczba : integer;
nast : wsk;
pop : wsk;
end;
procedure quicksort(var tab : array of integer; pocz, kon : integer);
var
tpocz, tkon, tmp, sr : integer;
begin
tpocz := pocz;
tkon := kon;
sr := tab[(tpocz + tkon) div 2];
repeat
while tab[tpocz] < sr do
inc(tpocz);
while tab[tkon] > sr do
dec(tkon);
if tpocz <= tkon then begin
tmp := tab[tpocz];
tab[tpocz] := tab[tkon];
tab[tkon] := tmp;
inc(tpocz);
dec(tkon);
end;
until tpocz > tkon;
if tkon > pocz then
quicksort(tab,pocz,tkon);
if tpocz < kon then
quicksort(tab,tpocz,kon);
end;
procedure sortuj(var pocz, kon : wsk);
var
tab : array of integer;
a, i : integer;
tmp : wsk;
begin
new(tmp);
if pocz = nil then
Writeln('nie ma zadnych elementow')
else
a := 0;
tmp := pocz;
while tmp <> nil do begin
tmp := tmp.nast;
a := a + 1;
end;
tmp := pocz;
setlength(tab,a);
for i := 1 to a do begin
tab[i] := tmp.liczba;
tmp := tmp.nast;
end;
quicksort(tab,1,a);
tmp := pocz;
i := 0;
while tmp <> nil do begin
i := i + 1;
tmp.liczba := tab[i];
tmp := tmp.nast;
end;
end;
Prosze o pomoc