Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. class!
  2.  
  3. package pkgtrue;
  4.  
  5. import javax.swing.JOptionPane;
  6.  
  7. public class Tree {
  8.  
  9. public void Insertar(int i, String content) {
  10. Nodo f = new Nodo(i);
  11. f.content = content;
  12.  
  13. if (raiz == null) {
  14. raiz = f;
  15. } else {
  16. Nodo aux = raiz;
  17. while (aux != null) {
  18. f.Raiz = aux;
  19. if (f.Piso >= aux.Piso) {
  20. aux = aux.derecha;
  21. } else {
  22. aux = aux.izquierda;
  23. }
  24.  
  25. }
  26. if (f.Piso < f.Raiz.Piso) {
  27. f.Raiz.derecha = f;
  28. }
  29. }
  30. }
  31. Nodo raiz;
  32.  
  33. public Tree() {
  34. raiz = null;
  35. }
  36.  
  37. public void Senda(Nodo f) {
  38. if (f != null) {
  39. Senda(f.izquierda);
  40. // JOptionPane.showMessageDialog(maldita sea :'v);
  41. System.out.println("Piso " + f.Piso + "Contenido " + f.content);
  42. Senda(f.derecha);
  43.  
  44. }
  45. }
  46.  
  47. private class Nodo {
  48.  
  49. public Nodo Raiz;
  50. public Nodo derecha;
  51. public Nodo izquierda;
  52. public int Piso;
  53. public Object content;
  54.  
  55. public Nodo(int location) {
  56. location = Piso;
  57. derecha = null;
  58. izquierda = null;
  59. content = null;
  60. }
  61. }
  62. }
  63. main!
  64.  
  65. package pkgtrue;
  66.  
  67. import javax.swing.JOptionPane;
  68.  
  69.  
  70. public class True {
  71.  
  72. public static void main(String[] args) {
  73. // int x=Integer.parseInt(JOptionPane.showInputDialog("Cuantos datos quiere generar dentro del arbol?"));
  74. Tree tree = new Tree();
  75. // for(int i=0; i<x;i++){
  76. // String uy=JOptionPane.showInputDialog("Que quieres insertar?");
  77. tree.Insertar(9,"uy");
  78. tree.Insertar(2,"a");
  79. tree.Insertar(3,"b");
  80.  
  81. //
  82. // }
  83. tree.Senda(tree.raiz);
  84.  
  85.  
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement