Advertisement
Guest User

Asd-Esercizio2-giugno2017-traccia2

a guest
Nov 14th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Algo_it(T,P){
  2. ct=T;
  3. cp=P;
  4. last=nil;
  5. stack_t=stack_x=stack_flag=stack_p=nil;
  6. while(ct!=nil or stack_t!=nil)do
  7. if(ct!=nil)then
  8. flag=0;
  9. ret=0;
  10. if(ct->key % 2 = 0 )then
  11. flag=1;
  12. push(stack_t,ct);
  13. push(stack_p,cp);
  14. push(stack_flag,flag);
  15. ct=ct->sx;
  16. cp=ct;
  17. else
  18. cp=top(stack_p);
  19. ct=top(stack_t);
  20. falg=top(stack_flag);
  21. if (last!=ct->dx)then
  22. x=ret;
  23. if(ct->dx!=nil)then
  24. push(stack_x,x);
  25. ct=ct->dx;
  26. cp=ct;
  27. else
  28. y=0
  29. if(flag=1 AND cp!=nil AND x+y=0)then
  30. if(cp->sx=ct)then
  31. ct->sx=cancella_root(ct);
  32. else
  33. ct->dx=cancella_root(ct);
  34. ret=x+y+flag;
  35. pop(stack_t);
  36. pop(stack_p);
  37. pop(stack_x);
  38. pop(stack_flag);
  39. las=ct;
  40. ct=nil;
  41. else
  42. y=ret;
  43. x=top(stack_x);
  44. if(flag=1 AND cp!=nil AND x+y=0)then
  45. if(cp->sx=ct)then
  46. ct->sx=cancella_root(ct);
  47. else
  48. ct->dx=cancella_root(ct);
  49. ret=x+y+flag;
  50. pop(stack_t);
  51. pop(stack_x);
  52. pop(stack_flag);
  53. pop(stack_p);
  54. las=ct;
  55. ct=nil;
  56. return ret;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement