Advertisement
Meruem

Inserimento in un albero

Apr 27th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tree_insert(t,o,chiave)
  2. {
  3.     var n={dato:o,left:null,right:null};
  4.     var cur=t.root;
  5.         if(t.root==null)
  6.         {
  7.             t.root=n;
  8.             return;
  9.         }
  10.             while(true)
  11.             {
  12.                 if(o[chiave]<= cur.dato[chiave])
  13.                 {
  14.                     if(cur.left==null)
  15.                     {
  16.                         cur.left=n;
  17.                         return;
  18.                     }else
  19.                         {
  20.                           cur=cur.left;
  21.                         }
  22.                 }else
  23.                     {
  24.                         if(cur.right==null)
  25.                         {
  26.                             cur.rigth=n;
  27.                             return;
  28.                         }else
  29.                         { cur=cur.right;
  30.                     }
  31.             }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement