private int descobrirAltura(NoArvore no)
        {
            if (no != null)
            {
                if (no.Nivel > this.altura)
                {
                    altura = no.Nivel;
                    return Math.Max(this.descobrirAltura(no.Esq), this.descobrirAltura(no.Dir));
                }
            }

            return altura;
        }
 public void inserir(String chave)
 {
     if (no == null)
     {
         no = new NoArvore(chave);
         no.Nivel = 1;
         no.Lado = 0;
     }
     else
     {
         no.inserir(chave);
     }
 }
Example #3
0
        public void inserir(String c)
        {
            //compara as duas strings
            int result = c.ToUpper().CompareTo(chave.ToUpper());

            //de acordo com o resultado, executar:
            //se o resultado da compara��o for menor que 0,
            //quer dizer que c � menor � menor que a chave
            if (result < 0)
            {
                if (esq == null){
                    esq = new NoArvore(c);
                    esq.Nivel = this.Nivel + 1;
                    esq.Lado = -1;
                }
                else
                    esq.inserir(c);
            }

            //se for maior que 0, quer dizer que c � maior
            else if (result > 0)
            {
                if (dir == null){
                    dir = new NoArvore(c);
                    dir.Nivel = this.Nivel + 1;
                    dir.Lado = 1;
                }
                else
                    dir.inserir(c);
            }
        }
Example #4
0
 public NoArvore(String c)
 {
     chave = c;
     esq = dir = null;
 }
 private NoArvore pesquisar(String c, NoArvore x)
 {
     if (x == null || c.ToUpper().CompareTo(x.Chave.ToUpper()) == 0)
         return x;
     else if (c.ToUpper().CompareTo(x.Chave.ToUpper()) < 0)
         return pesquisar(c, x.Esq);
     else
         return pesquisar(c, x.Dir);
 }
        private void reordenarAlturaNosArvore(NoArvore no)
        {
            if (no != null)
            {
                no.Altura = this.altura - (no.Nivel - 1);
                //no.Lado = 120 * no.Altura * no.Lado;

                if (no.Esq != null)
                {
                    if (no.Lado == 0)
                    {
                        no.Esq.Lado = 120 * no.Altura * no.Esq.Lado;
                    }
                    else
                    {
                        no.Esq.Lado = no.Lado * no.Altura * no.Esq.Lado;
                    }
                }

                if (no.Dir != null)
                {
                    if (no.Lado == 0)
                    {
                        no.Dir.Lado = 120 * no.Altura * no.Dir.Lado;
                    }
                    else
                    {
                        no.Dir.Lado = no.Lado * no.Altura * no.Dir.Lado;
                    }

                }

                reordenarAlturaNosArvore(no.Esq);
                reordenarAlturaNosArvore(no.Dir);
            }
        }