Advertisement
Guest User

Es3vers2

a guest
Jul 29th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Algo(T,k)
  2. bst_node last = null, cur = T, figlio = NIL
  3.  
  4. while(cur or figlio ){
  5.  
  6. if(cur != NIL){
  7.  
  8. if(cur.k != k){
  9.  
  10. if(ABS(cur.k - k) < ABS(last.k - k))
  11. last = cur
  12.  
  13. if(cur.k > k)
  14. cur=cur.sx
  15. else cur = cur.dx
  16.  
  17. }else{
  18.  
  19. if(cur.dx != NIL and cur.sx != NIL){ //Nel caso ci sono 2 figli salva solo il destro e cur va a sinistra
  20. figlio=cur.dx;
  21. cur=cur.sx
  22. }else if(cur.sx = NIL){
  23. cur=cur.dx
  24. }else cur = cur.sx
  25.  
  26. }
  27.  
  28.  
  29. }else if(figlio!=NIL){ //Quando cur รจ diventato NIL se c'รจ ancora il destro da vedere lo rimette in cur
  30. cur = figlio //e mette figlio a NIL cosi dopo termina l'algoritmo(l'idea tua Bruno)
  31. figlio = NIL
  32. }
  33.  
  34. }
  35.  
  36. return last;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement