Пример #1
0
        private static void XeqListaEncadeada()
        {
            ProgramBase.Cabecalho();

            Console.WriteLine("De que tamanho deseja a lista: ");
            var tamanho = int.Parse(Console.ReadLine());

            var listChain = new ListChain(tamanho);

            listChain.CriaLista();

            var acao = 0;

            do

            {
                acao = ProgramBase.GetListaSeqOpcao();

                if (acao == 1)
                {
                    XeqInsereEncadeado(listChain);
                }
                else if (acao == 2)
                {
                    XeqDeleteEncadeadoByIndex(listChain);
                }
                else
                {
                    break;
                }
            }while (acao != 3);

            ProgramBase.Fim();
        }
Пример #2
0
        private static void XeqDeleteEncadeadoByIndex(ListChain listChain)
        {
            var valor  = 0;
            var parsed = false;

            while (!parsed)
            {
                Console.WriteLine("Digite o índice do valor que deseja eliminar: ");
                parsed = int.TryParse(Console.ReadLine(), out valor);
            }

            listChain.DeleteByIndex(valor);

            XeqListListaEncadeado(listChain);
        }
Пример #3
0
        private static void XeqInsereEncadeado(ListChain listChain)
        {
            var mensagem = "Valor inserido com sucesso";

            Console.WriteLine("Digite o valor: ");
            var valor = Console.ReadLine();

            if (!listChain.Insere(valor))
            {
                mensagem = "Erro: Lista cheia";
            }

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(mensagem);
            Console.ForegroundColor = ConsoleColor.Green;

            XeqListListaEncadeado(listChain);
        }
Пример #4
0
        private static void XeqListListaEncadeado(ListChain listChain)
        {
            var regChain = listChain.ListLista();

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine($"Apontador de início: {regChain.PonteiroInicio}");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine($"Apontador de disponibilidade: {regChain.PonteiroDisponivel}");
            Console.ForegroundColor = ConsoleColor.Cyan;

            for (int i = 0; i < regChain.Lista.Length; i++)
            {
                string indice, valor;

                if (regChain.Indice[i] < 0)
                {
                    indice = regChain.Indice[i].ToString();
                }
                else
                {
                    indice = $" {regChain.Indice[i].ToString()}";
                }

                if (regChain.Lista[i] == string.Empty)
                {
                    valor = "-------";
                }
                else
                {
                    valor = regChain.Lista[i];
                }

                Console.WriteLine($"Posição: {i} - Aponta para: {indice} - Valor: {valor}");
            }

            Console.ForegroundColor = ConsoleColor.Green;
        }