Advertisement
disiodj

Alberi_Definizioni

Dec 6th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. CREATE-TREE()
  2. //T è un nuovo nodo
  3. T.right = NULL;
  4. T.left = NULL;
  5. T.info = NULL;
  6. T.root = T;
  7. return T;
  8.  
  9. IS-EMPTY(t)
  10. //funzione che restituisce true se l'albero è vuoto
  11. if(t.root == null)
  12. return true
  13. else
  14. return false;
  15.  
  16. ROOT(t)
  17. //funzione che restituisce il riferimento alla radice dell'albero
  18. return t.root;
  19.  
  20. LEFT(t, n)
  21. //ritorna il riferimento al nodo sinistro del nodo n
  22. return n.lef;
  23.  
  24. RIGHT(t, n)
  25. //restituisce il riferimento al nodo destro del nodo n
  26. return n. right;
  27.  
  28. INFO(t,n)
  29. //restituisce le informazioni satellite del nodo n
  30. return n.info;
  31.  
  32. TWO_CHILDREN(n)
  33. //ritorna TRUE se il nodo n ha due figli, false altrimenti
  34. if((n.right && n.left)!=NULL)
  35. return true;
  36. else
  37. return false;
  38.  
  39. ADD-ROOT(t,z)
  40. //aggiunge il nodo radice con valore z all'albero t.
  41. temp.info = z;
  42. temp.right=null;
  43. temp.left = null;
  44. t.root = temp;
  45.  
  46. ONLY-LEFT(t) versione 1
  47. //ritorna true se tutti i figli sinistri dell'albero t hanno solo i figli sinistri.
  48. if(t.right!=NULL)
  49. return false;
  50. else
  51. if(t.left!=NULL)
  52. return ONLY-LEFT(t.left);
  53. return TRUE;
  54. ONLY-LEFT(t) versione 2
  55. if(t.right!=NULL)
  56. return false;
  57. else
  58. if(t!=null)
  59. return ONLY-LEFT(t.left)
  60. return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement