Napisalem rekurencyjna procedure do tworzenia listy, ale dla dlugiej listy nastepuje przepelnienie stosu. Problem jest nastepujacy: trzeba przerobic rekurencje na petle (najlepiej while). Najwazniejsze zeby procedura miala identyczne dzialanie. Wydaje sie proste ale...
Ponizej jest procedura, jesli ktos wie jak to powinno wygladac po przerobce bardzo prosze o pomoc (moze ktos mnie chociaz naprowadzi zebym znalazl blad).
procedure dodaj(var head:wsk;d:SearchRec);
var nowy:wsk;
begin
if head = nil then
begin
new(head);
head^.plik := d;
head^.nast := nil;
exit;
end;
if (IsDir(d.attr) and IsDir(head^.plik.attr))
or ((not IsDir(d.attr)) and (not Isdir(head^.plik.attr)))
or (IsDir(d.attr) and (not IsDir(head^.plik.attr)))
then
begin
if ((head^.plik.name > d.name))
or (IsDir(d.attr) and (not IsDir(head^.plik.attr)))
then
begin
new(nowy);
nowy := head;
head^.plik := d;
head^.nast := nowy;
exit;
end;
end;
dodaj(head^.nast,d);
end;
Jeszcze jakby co deklaracja typow:
type wsk = ^element;
element = record
plik:SearchRec;
nast:wsk;
end;
A funkcja IsDir ma postac:
function IsDir(attr:byte):boolean;
begin
if (attr shr 4) mod 2 0 then IsDir := true else IsDir := false;
end;