예제 #1
0
        public void Remover(int NoRemover)
        {
            Buscar(NoRemover);
            var noPai = NoEncontrado.GetPai();

            if (NoEncontrado != null)
            {
                if (NoEncontrado.GetFilhoEsq() == null && NoEncontrado.GetFilhoDir() == null)
                {
                    if (noPai.GetFilhoEsq() == NoEncontrado)
                    {
                        noPai.InserirFilhoEsq(null);
                        Console.WriteLine("\nNó removido!");
                        return;
                    }
                    else
                    {
                        noPai.InserirFilhoDir(null);
                        Console.WriteLine("\nNó removido!");
                        return;
                    }
                }

                if (NoEncontrado.GetFilhoEsq() != null && NoEncontrado.GetFilhoDir() != null)
                {
                    Console.WriteLine("\nO nó não pode ser removido!");
                    return;
                }

                No filhoExistente;
                if (NoEncontrado.GetFilhoEsq() != null)
                {
                    filhoExistente = NoEncontrado.GetFilhoEsq();
                }
                else
                {
                    filhoExistente = NoEncontrado.GetFilhoDir();
                }

                if (noPai.GetFilhoEsq() == NoEncontrado)
                {
                    noPai.InserirFilhoEsq(filhoExistente);
                    Console.WriteLine("\nNó removido!");
                }
                else
                {
                    noPai.InserirFilhoDir(filhoExistente);
                    Console.WriteLine("\nNó removido!");
                }
            }
            NoEncontrado = new No();
        }
예제 #2
0
        public int Grau(int No)
        {
            Buscar(No);
            if (NoEncontrado.GetFilhoEsq() != null && NoEncontrado.GetFilhoDir() != null)
            {
                return(2);
            }
            if (NoEncontrado.GetFilhoEsq() != null || NoEncontrado.GetFilhoDir() != null)
            {
                return(1);
            }

            NoEncontrado = new No();
            return(0);
        }