luca_mazz1

RIC/IT 02/2018

Feb 1st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. ALGO(T)
  2. curr=T, last=next=NIL
  3. ret=1
  4. a=b=0
  5. S_T=S_x=NIL
  6.  
  7. while (curr != NIL || S_T != NIL) do
  8. if (curr != NIL) then
  9. ret=1
  10. x= curr->key % 2
  11. push(S_T, curr)
  12. push(S_x, x)
  13. next= curr->dx
  14. else
  15. curr= top(S_T)
  16. if (last != curr-> sx && curr->sx != NIL) then
  17. x= top(S_x)
  18. pop(S_x)
  19. a= ret
  20. x=a+x
  21. push(S_x, x)
  22. next= curr->sx
  23. else
  24. pop(S_T)
  25. x= top(S_x)
  26. pop(S_x)
  27. if (curr->sx != NIL) then
  28. y= ret
  29. else
  30. y= 1
  31. ret= x*y*curr->key
  32. next= NIL
  33. last=curr
  34. curr=next
  35. return ret
Advertisement
Add Comment
Please, Sign In to add comment