コード例 #1
0
        public void Insere(int n, ref Arvore RAIZ)
        {
            Arvore temp, subarv, noDesb = null;

            this.info = n;
            this.fb   = 0;
            if (RAIZ == null)
            {
                RAIZ = this;
            }
            else
            {
                temp = RAIZ;
                while (temp != null)
                {
                    subarv = temp;
                    if (n <= temp.info)
                    {
                        temp = temp.sae;
                        if (temp == null)
                        {
                            subarv.sae = this;
                        }
                        subarv.fb--;
                    }
                    else
                    {
                        temp = temp.sad;
                        if (temp == null)
                        {
                            subarv.sad = this;
                        }
                        subarv.fb++;
                    }
                    if (subarv.fb > 1 || subarv.fb < -1)
                    {
                        noDesb = subarv;
                    }
                }
                if (noDesb != null)
                {
                    if (noDesb.fb > 0)
                    {
                        BalanceamentoEsq(ref RAIZ, noDesb);
                    }
                    else
                    {
                        BalanceamentoDir(ref RAIZ, noDesb);
                    }
                }
            }
        }
コード例 #2
0
 public void BalanceamentoDir(ref Arvore RAIZ, Arvore noDesb)
 {
     if (noDesb == RAIZ)
     {
         RAIZ      = noDesb.sae;
         noDesb.fb = 0;
         RAIZ.fb++;
     }
     else
     {
         Arvore temp = RAIZ;
         while (temp.sae != noDesb)
         {
             temp = temp.sae;
         }
         temp.sae = noDesb.sae;
         temp.fb--;
         temp.sae.fb++;
         noDesb.fb = 0;
     }
     noDesb.sae.sad = noDesb;
     noDesb.sae     = null;
 }
コード例 #3
0
 public void BalanceamentoEsq(ref Arvore RAIZ, Arvore noDesb)
 {
     if (noDesb == RAIZ)
     {
         RAIZ      = noDesb.sad;
         noDesb.fb = 0;
         RAIZ.fb--;
     }
     else
     {
         Arvore temp = RAIZ;
         while (temp.sad != noDesb)
         {
             temp = temp.sad;
         }
         temp.sad = noDesb.sad;
         temp.fb--;
         temp.sad.fb--;
         noDesb.fb = 0;
     }
     noDesb.sad.sae = noDesb;
     noDesb.sad     = null;
 }
コード例 #4
0
 public Arvore()  // Construtor
 {
     info = 0;
     sae  = sad = null;
 }