Beispiel #1
0
        private void AtribuirValores()
        {
            Raiz = Numeros.Max();
            int posicaoRaiz = Array.IndexOf(Numeros, Raiz);

            List <int> numerosEsquerda = new List <int>();
            List <int> numerosDireita  = new List <int>();

            for (int i = default; i < Numeros.Length; i++)
            {
                if (i < posicaoRaiz)
                {
                    numerosEsquerda.Add(Numeros[i]);
                }
                else if (i > posicaoRaiz)
                {
                    numerosDireita.Add(Numeros[i]);
                }
            }

            GalhoEsquerda = Galho.Criar(numerosEsquerda.ToArray());
            GalhoDireita  = Galho.Criar(numerosDireita.ToArray());

            TamanhoMaiorGalho = GalhoEsquerda.Numeros.Length > GalhoDireita.Numeros.Length ? GalhoEsquerda.Numeros.Length : GalhoDireita.Numeros.Length;
        }
        /// <summary>
        /// Cria o galho com seus numeros em ordem decrescente
        /// </summary>
        /// <param name="numeros"></param>
        /// <returns></returns>
        public static Galho Criar(int[] numeros)
        {
            Galho galho = new Galho()
            {
                Numeros = numeros.OrderByDescending(n => n).ToArray()
            };

            return(galho);
        }