Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: Java  |  size: 0.68 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class ArvoreBinaria {
  2.  
  3.         public static class Node {
  4.                 int dado;
  5.                 Node esq;
  6.                 Node dir;
  7.  
  8.                 Node ( int dado ) {
  9.                         this.dado = dado;
  10.                         this.esq = null;
  11.                         this.dir = null;
  12.                 }
  13.  
  14.         }
  15.  
  16.         public static class Arvore {
  17.                 Node raiz;
  18.                 Node aux;
  19.  
  20.                 Arvore ( Node raiz ) {
  21.                         this.raiz = raiz;
  22.                 }
  23.  
  24.                 public void inserir(Node seila) {
  25.                         if ( this.raiz == null ) {
  26.                                 seila = raiz;
  27.                         }
  28.                         else inserir(this.raiz, seila);
  29.                 }
  30.  
  31.                 public void inserir (Node raiz, Node seila ) {
  32.                         if (raiz == null) raiz = new Node(seila.dado);
  33.                         else {
  34.                                 if (raiz.dado > seila.dado ) {
  35.                                         inserir(raiz.esq, seila);
  36.                                 }
  37.                                 else inserir(raiz.dir, seila);
  38.                         }
  39.                 }
  40.         }
  41. }