Lucassim

Tree.oz

Jul 16th, 2013
498
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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}
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×