Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Algo_IT(T){
- ret=-1;
- curr=T;
- last=NIL; //Inizializzo variabili
- stack_dpsx;
- dpsx=-1;
- dpdx=-1;
- stack_curr=NIL;
- max=0-1;
- while(curr!=NIL || stack_curr!=NIL){
- if(curr!=NIL){
- ret=-1; // ogni qualvolta scendo inizializzon ret come nell'algo ric
- push(satck_curr,curr);
- curr=curr->sx;
- }else{ //risalita
- curr=top(stack_curr);
- if(curr->dx!=NIL && curr->dx!=last){ //devo scendere a DESTRA quindi salvo il sinistro e scendo
- dpsx=ret;
- push(stack_dspx,dpsx);
- ret=-1;
- curr=curr->dx;
- }else{
- if(curr->dx==last){ //sto risalendo da destra quindi dpdx sarà ret appena calcolato mentre
- dpdx=ret; //dpsx lo trovo nello stack
- dpsx=top(stack_dpsx);
- pop(stack_dpsx);
- }else{ //il figlio destro è null quindi dpdx sarà -1 mentre dpsx ret perchè non è
- dpdx=-1; //stato modificato
- dpsx=ret;
- }
- max=MAX(dpsx,dpdx); //operazioni dell'algoritmo ricorsivo
- if(max>=0)
- max++;
- if(curr->key%2==0)
- ret=Max(0,max);
- else
- ret=max;
- last=curr;
- curr=NIL;
- Pop(stack_curr);
- }
- }
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment