Advertisement
luca_mazz1

[ASD] RIC-IT 28/06/2017

Jan 19th, 2019
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /*
  2. ALGO(T,P)
  3. flag= 0
  4. ret= 0
  5. if T != NIL then
  6. if T->key % 2 = 0 then
  7. flag= 1
  8. x= ALGO(T->sx, T)
  9. y= ALGO(T->dx, T)
  10.  
  11. if flag=1 AND P != NIL AND x+y=0 then
  12. if P->sx= T then
  13. P->sx= CANCELLA-ROOT(T)
  14. else
  15. P->dx= CANCELLA-ROOT(T)
  16. ret= x+y+flag
  17. return ret
  18. */
  19.  
  20. ALGO_IT(T, P)
  21. currT= T, currP= P, last=nextT=nextP= NIL
  22. ret=flag=0
  23. S_T= S_P= S_flag= S_x= NIL
  24.  
  25. while (currT != NIL || S_T != NIL) do
  26. if (currT != NIL) then
  27. ret= 0
  28. flag= 0
  29.  
  30. if (currT->key % 2 == 0) then
  31. flag= 1
  32.  
  33. push(S_T, currT)
  34. push(S_P, currP)
  35. push(S_flag, flag)
  36. nextT= currT->sx
  37. nextP= currT
  38.  
  39. else
  40. currT= top(S_T)
  41. currP= top(S_P)
  42. flag= top(S_flag)
  43.  
  44. if (last != currT->dx && currT->dx != NIL) then
  45. x= ret
  46. push(S_x, x)
  47. nextT= currT->dx
  48. nextP= currT
  49.  
  50. else
  51. pop(S_T)
  52. pop(S_P)
  53. pop(S_flag)
  54. x= top(S_x)
  55. pop(S_x)
  56.  
  57. if (currT->dx != NIL) then
  58. y= ret
  59. else
  60. y= 0
  61.  
  62. if (flag == 1 && currP != NIL && x+y= 0) then
  63. if (currP->sx == currT) then
  64. currP->sx= CANCELLA-ROOT(currT)
  65. else
  66. currP->dx= CANCELLA-ROOT(currT)
  67. ret= x+y+flag
  68. nextT= NIL
  69.  
  70. last= currT
  71. currT= nextT
  72. currP= nextP
  73.  
  74. return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement