Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare
- class Tree\4
- attr
- Raiz %tree(V Izq Der)
- meth inic
- Raiz:=nil
- end
- meth printRaiz
- {Browse @Raiz}
- end
- meth insertNodo(A N ?T)
- case A of
- nil then T=N
- [] tree(X L R) then
- if N.1 < X then
- local Aux in
- {self insertNodo(L N Aux)}
- T=tree(X Aux R)
- end
- else
- local Aux in
- {self insertNodo(R N Aux)}
- T=tree( X L Aux )
- end
- end
- end
- end
- meth insertar(N)
- local A in
- {self insertNodo(@Raiz N A)}
- Raiz:=A
- end
- end
- end
- declare T={New Tree inic}
- {T insertar(tree(2 nil nil))}
- {T insertar(tree(1 nil nil))}
- {T insertar(tree(4 nil nil))}
- {T insertar(tree(3 nil nil))}
- {T printRaiz}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement