Advertisement
Lucassim

Tree.oz

Jul 16th, 2013
2,567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 0.78 KB | None | 0 0
  1. declare
  2.    
  3. class Tree\4
  4.    attr
  5.       Raiz %tree(V Izq Der)
  6.  
  7.    meth inic
  8.       Raiz:=nil
  9.    end
  10.      
  11.    meth printRaiz
  12.       {Browse @Raiz}
  13.    end
  14.    
  15.    meth insertNodo(A N ?T)
  16.       case A of
  17.      nil then T=N
  18.       [] tree(X L R) then
  19.      if N.1 < X then
  20.         local Aux in
  21.            {self insertNodo(L N Aux)}
  22.            T=tree(X Aux R)
  23.         end
  24.        
  25.      else
  26.         local Aux in
  27.            {self insertNodo(R N Aux)}
  28.            T=tree( X L Aux )
  29.         end
  30.      end
  31.       end
  32.    end
  33.  
  34.    meth insertar(N)
  35.       local A in
  36.      {self insertNodo(@Raiz  N A)}
  37.      Raiz:=A
  38.       end
  39.      
  40.    end
  41.    
  42.    
  43. end
  44.  
  45.  
  46. declare T={New Tree inic}
  47. {T insertar(tree(2 nil nil))}
  48. {T insertar(tree(1 nil nil))}
  49. {T insertar(tree(4 nil nil))}
  50. {T insertar(tree(3 nil nil))}
  51. {T printRaiz}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement