Advertisement
Giuliox

28/06/2017 Traccia 1 Ricor->iter

Jan 11th, 2018
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Algo(T,a,b)
  2. St,Sir
  3. currT = T
  4. Ir=0
  5. ret = Nil
  6. while(St != Nil or currT != Nil)
  7. if ir == 0 then
  8. if currT != nil then
  9. push(St,currT)
  10. if currT->key < a then
  11. currT = currT->Sx
  12. push(Sir, 1)
  13. else if currT->key > b then
  14. currT = currT->Dx
  15. push(Sir, 2)
  16. else
  17. currT = currT->Sx
  18. push(Sir, 3)
  19. else
  20. ret = currT
  21. ir = Top(sir)
  22. pop(Sir)
  23. currT = Top(St)
  24. pop(St)
  25. else if ir == 1 then
  26. currT->sx = ret
  27. ret = currT
  28. ir = Top(sir)
  29. pop(Sir)
  30. currT = Top(St)
  31. pop(St)
  32. else if ir == 2 then
  33. currT->dx = ret
  34. ret = currT
  35. ir = Top(sir)
  36. pop(Sir)
  37. currT = Top(St)
  38. pop(St)
  39. else if ir == 3 then
  40. currT->sx = ret
  41. push(St, currT)
  42. currT = currT->dx
  43. push(Sir,4)
  44. ir = 0
  45. else if ir == 4 then
  46. currT->dx = ret
  47. currT = CANCELLA_RADICE(currT)
  48. ret = currT
  49. ir = Top(sir)
  50. pop(Sir)
  51. currT = Top(St)
  52. pop(St)
  53. return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement