Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class!
- package pkgtrue;
- import javax.swing.JOptionPane;
- public class Tree {
- public void Insertar(int i, String content) {
- Nodo f = new Nodo(i);
- f.content = content;
- if (raiz == null) {
- raiz = f;
- } else {
- Nodo aux = raiz;
- while (aux != null) {
- f.Raiz = aux;
- if (f.Piso >= aux.Piso) {
- aux = aux.derecha;
- } else {
- aux = aux.izquierda;
- }
- }
- if (f.Piso < f.Raiz.Piso) {
- f.Raiz.derecha = f;
- }
- }
- }
- Nodo raiz;
- public Tree() {
- raiz = null;
- }
- public void Senda(Nodo f) {
- if (f != null) {
- Senda(f.izquierda);
- // JOptionPane.showMessageDialog(maldita sea :'v);
- System.out.println("Piso " + f.Piso + "Contenido " + f.content);
- Senda(f.derecha);
- }
- }
- private class Nodo {
- public Nodo Raiz;
- public Nodo derecha;
- public Nodo izquierda;
- public int Piso;
- public Object content;
- public Nodo(int location) {
- location = Piso;
- derecha = null;
- izquierda = null;
- content = null;
- }
- }
- }
- main!
- package pkgtrue;
- import javax.swing.JOptionPane;
- public class True {
- public static void main(String[] args) {
- // int x=Integer.parseInt(JOptionPane.showInputDialog("Cuantos datos quiere generar dentro del arbol?"));
- Tree tree = new Tree();
- // for(int i=0; i<x;i++){
- // String uy=JOptionPane.showInputDialog("Que quieres insertar?");
- tree.Insertar(9,"uy");
- tree.Insertar(2,"a");
- tree.Insertar(3,"b");
- //
- // }
- tree.Senda(tree.raiz);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement