🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #3024

Problems implementing an AVL Tree ...

#3024
From: Gustavo
Date: Mon, 25 May 1998 00:00
124 lines
3468 bytes
I am writing a class that functions like an AVL Tree, I wrote it in Delphi
and it functions well, the problem is :

   when I want to insert a value I pass through the nodes(left or right
child), when  I pass to the function the null node, then it is the time to
create a node, the problem is that the new object that I create does not
reference the one I pass to the function.
here is the code :

   This is the node component

public class TTermo
{
  //---------------------------------------------------------
 // vari�veis
 protected String FTexto;
 protected int FBalanceamento;
 public TTermo NoDireito;
 public TTermo NoEsquerdo;
 boolean FPreenchido;

 //---------------------------------------------------------
 // m�todos publicos
 public void setaTexto(String valor)
 {
   FTexto = valor;
   FPreenchido = true;
 }

 //---------------------------------------------------------
  public String pegaTexto()
  {
    return FTexto;
  }

  //---------------------------------------------------------
  public void setaBalanceamento(int valor)
 {
   FBalanceamento = valor;
 }

 //---------------------------------------------------------
  public int pegaBalanceamento()
  {
    return FBalanceamento;
  }

   //---------------------------------------------------------
  public void setaPreenchido(boolean valor)
 {
   FPreenchido = valor;
 }

 //---------------------------------------------------------
  public boolean pegaPreenchido()
  {
    return FPreenchido;
  }

  //---------------------------------------------------------
 // construtores

 public TTermo()
 {

    NoDireito = null;
    NoEsquerdo = null;

   FTexto = "";
   FBalanceamento = 0;
 }


}

This is the function to insert:


protected  void insert(String valor ,TTermo no ,Boolean h)
{

  String auxtexto;

  if (no == null )



       FTermoIns = new TTermo();
       FTermoIns.setaTexto(valor);
       h = Boolean.TRUE;
       FNumeroTermos ++;
       no = FTermoIns;
     }

  else
    {
       // para facilitar o entendimento
        auxtexto = no.pegaTexto().toLowerCase();
       if (valor.toLowerCase().compareTo(auxtexto) < 0)
         {
           retorno = insert(valor,no.NoEsquerdo, h);
           if (h == Boolean.TRUE )
              balanceEsquerdaIns(no, h);
         }
        else
          if (valor.toLowerCase().compareTo(auxtexto) > 0)
            {
             insert(valor,no.NoDireito, h);
              if (h == Boolean.TRUE)
                balanceDireitaIns(no , h);
            }
      }

}


----------------------------------------------------------------------------
----------------
Gustavo Dutra Martins                       Interbrain Sistemas
        327-5296                                           205-0143
dutra@trip.com.br                      gustavo@interbrain.com.br
----------------------------------------------------------------------------
---------------
Technical Details
Message-ID: <6kcfmt$6gm6@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 1089d0,aa7241afe30c6361,start
X-Google-Attributes: gid1089d0,public
From: "Gustavo" <dutra@trip.com.br>
Subject: Problems implementing an AVL Tree ...
Date: 1998/05/25
Message-ID: <6kcfmt$6gm6@forums.borland.com>
X-Deja-AN: 356414155
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.api