cecema

Untitled

Jan 12th, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. Algo_IT(T){
  2. ret=-1;
  3. curr=T;
  4. last=NIL; //Inizializzo variabili
  5. stack_dpsx;
  6. dpsx=-1;
  7. dpdx=-1;
  8. stack_curr=NIL;
  9. max=0-1;
  10. while(curr!=NIL || stack_curr!=NIL){
  11. if(curr!=NIL){
  12. ret=-1; // ogni qualvolta scendo inizializzon ret come nell'algo ric
  13. push(satck_curr,curr);
  14. curr=curr->sx;
  15. }else{ //risalita
  16. curr=top(stack_curr);
  17. if(curr->dx!=NIL && curr->dx!=last){ //devo scendere a DESTRA quindi salvo il sinistro e scendo
  18. dpsx=ret;
  19. push(stack_dspx,dpsx);
  20. ret=-1;
  21. curr=curr->dx;
  22. }else{
  23. if(curr->dx==last){ //sto risalendo da destra quindi dpdx sarà ret appena calcolato mentre
  24. dpdx=ret; //dpsx lo trovo nello stack
  25. dpsx=top(stack_dpsx);
  26. pop(stack_dpsx);
  27. }else{ //il figlio destro è null quindi dpdx sarà -1 mentre dpsx ret perchè non è
  28. dpdx=-1; //stato modificato
  29. dpsx=ret;
  30. }
  31. max=MAX(dpsx,dpdx); //operazioni dell'algoritmo ricorsivo
  32. if(max>=0)
  33. max++;
  34. if(curr->key%2==0)
  35. ret=Max(0,max);
  36. else
  37. ret=max;
  38. last=curr;
  39. curr=NIL;
  40. Pop(stack_curr);
  41. }
  42. }
  43. }
  44. return ret;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment