Buongiorno mi aiutate a tradurre questo algoritmo ricorsivo in iterativo con l'uso dello stack
Algo(T,K_1,K_2,L)
if T=!Nil do
L'=Algo(T-->f1,k_1,k_2,L)
L'=Algo(T-->f2,k_1,k_2,')
L'=Algo(T-->f3,k_1,k_2,L')
if k_1<T-->Key<k_2
L=Alloca_Nodo()
L-->Key=T-->Key
L-->next=L'
else
L=L'
return L
io ho fatto cosi:
algo_it(T,K1,K2,L)
currT=T;
currL=L;
lastT=null;
StackT=null;
StackRet=null;
StackL=null;
nextT=null;
nextL=null;
ret=null;
while(currT!=NULL || StackT!=null)do
if(currT!=null)then
StackT=Push(StackT, currT);
StackL=Push(StackL, L);
nextT=currT-->f1;
else
StackT=Push(StackT, currT);
StackL=Push(StackL, L);
nextT=currT-->f2;
nextL=L';
else
currT=Top(StackT);
L=Top(StackL);
if((lastT!=currT-->f3|| lastT!=currT-->f2) && (currT-->f3!=null|| currT-->f2!=null))then
L'=ret;
StackRet=Push(StackT,ret);
else
if( currT-->f3!=null)then
L'=ret;
Ret=Top(StackT);
else
if(currT-->f2!=null) then
L'=ret
else
last=currT;
currT=nextT;
currL= nextL;
StackT=Pop(StackT);
StackL=Pop(StackL);
StackRet=Pop(StackRet);
if(k1 <= currT <= k2)then
L=Alloca_Nodo();
L-->Key= currT-->Key;
L-->next=L';
else
L=L'
return L
Grazie in anticipo