예제 #1
0
        static void Main(string[] args)
        {
            lista1.Agregar(73489);
            lista1.Agregar(12978);
            lista1.Agregar(48);
            lista1.Agregar(43);
            lista1.Agregar(1092);
            lista1.Transversa();

            quickSort(1, lista1.getSize());
            lista1.Transversa();
        }
        static void Main(string[] args)
        {
            Lista_Ligada lista = new Lista_Ligada();

            lista.Agregar(77);
            lista.Agregar(34);
            lista.Agregar(68);
            lista.Agregar(24);
            lista.Agregar(75);
            lista.Transversa();

            Lista_Ligada mergeSort = new Lista_Ligada();

            mergeSort = MergeSortMethod(lista);
            mergeSort.Transversa();
            //Lista_Ligada izq = new Lista_Ligada();
            //izq.Agregar(1);
            //izq.Agregar(3);
            //izq.Agregar(5);
            //izq.Agregar(7);
            //izq.Transversa();

            //Lista_Ligada der = new Lista_Ligada();
            //der.Agregar(2);
            //der.Agregar(4);
            //der.Agregar(6);
            //der.Agregar(8);
            //der.Agregar(10);
            //der.Agregar(12);
            //der.Transversa();

            //Lista_Ligada merged = Merge(izq, der);
            //merged.Transversa();
        }
예제 #3
0
        static void Main(string[] args)
        {
            // Selection Sort
            Lista_Ligada lista = new Lista_Ligada();

            lista.Agregar(4);
            lista.Agregar(5);
            lista.Agregar(8);
            lista.Agregar(2);
            lista.Agregar(9);
            lista.Agregar(3);
            lista.Agregar(1);
            lista.Agregar(8);
            lista.Agregar(9);
            lista.Agregar(2);
            lista.Agregar(7);
            lista.Agregar(5);
            lista.Transversa();
            // Datos necesarios
            int cantidad = lista.getSize() + 1;
            int iMenor   = 0;
            int temporal = 0;

            // Ascendente
            Console.WriteLine("Lista Ordenada Ascendente");
            for (int i = 0; i < cantidad - 1; i++)
            {
                //El indice menor es la posición actual desde donde comenzamos
                iMenor = i;
                // Encontramos el nuevo indice del menor
                for (int j = i + 1; j < cantidad; j++)
                {
                    if (lista[j] < lista[iMenor])
                    {
                        iMenor = j;
                    }
                }
                temporal      = (int)lista[i];
                lista[i]      = lista[iMenor];
                lista[iMenor] = temporal;
            }
            lista.Transversa();
            // Descendente
            Console.WriteLine("Lista Ordenada Descendente");
            for (int i = 1; i < cantidad; i++)
            {
                //El indice menor es la posición actual desde donde comenzamos
                iMenor = i;
                // Encontramos el nuevo indice del menor
                for (int j = i + 1; j < cantidad; j++)
                {
                    if (lista[j] > lista[iMenor])
                    {
                        iMenor = j;
                    }
                }
                temporal      = (int)lista[i];
                lista[i]      = lista[iMenor];
                lista[iMenor] = temporal;
            }
            lista.Transversa();

            // Ejercicio Programando el orden con 2 listas...
            Lista_Ligada listaResultado = new Lista_Ligada();
            int          cantidadLista  = lista.getSize() + 1;
            int          indiceBorrar   = 0;
            int          menor          = 0;
            int          mayor          = (int)lista[1];

            for (int i = 1; i < cantidadLista; i++)
            {
                menor = mayor;
                for (int j = 1; j < cantidadLista; j++)
                {
                    // Mientras busco el menor, voy buscando el mayor disponible para luego igualarlo
                    // Para luego hallar menores en base al mayor...
                    if (lista[i] > mayor && lista[i] > 0)
                    {
                        mayor = (int)lista[i];
                    }
                    // Recorro la lista y encuentro el menor
                    if (lista[j] < menor && lista[j] > 0)
                    {
                        menor        = (int)lista[j];
                        indiceBorrar = j;
                    }
                }
                lista[indiceBorrar] = 0;
                listaResultado.Agregar(menor);
            }
            Console.WriteLine("Selection Sort 2 Listas");
            listaResultado.Transversa();
        }
예제 #4
0
        static void Main(string[] args)
        {
            Lista_Ligada lista = new Lista_Ligada();

            lista.Agregar(5);
            lista.Agregar(2);
            lista.Agregar(4);
            lista.Agregar(8);
            lista.Transversa();
            Console.WriteLine(lista[1]);
            Console.WriteLine(lista[2]);
            Console.WriteLine(lista[3]);
            Console.WriteLine(lista[4]);
            //Insertion Sort
            int cantidad     = lista.getSize() + 1;
            int indexAgujero = 0;
            int dato         = 0;

            // Ascendente
            //Recorremos los elementos
            for (int i = 0; i < cantidad; i++)
            {
                //Obtenemos el dato
                dato = (int)lista[i];
                //Indicamos la posición del agujero
                indexAgujero = i;
                //Recorremos los elementos hacia el agujero
                while (indexAgujero > 0 && lista[indexAgujero - 1] > dato)
                {
                    lista[indexAgujero] = lista[indexAgujero - 1];
                    indexAgujero       -= 1;
                }
                //Le colocamos al agujero el dato correspondiente
                lista[indexAgujero] = dato;
                //lista.Transversa();
            }
            //Mostrar lista ordenada
            Console.WriteLine("Lista Ordenada");
            lista.Transversa();

            // Descendente
            //Insertion Sort
            int size       = lista.getSize() + 1;
            int indiceHole = 0;
            int numerito   = 0;

            // Ascendente
            //Recorremos los elementos
            for (int i = 2; i < size; i++)
            {
                //Obtenemos el dato
                numerito = (int)lista[i];
                //Indicamos la posición del agujero
                indiceHole = i;
                //Recorremos los elementos hacia el agujero
                while (indiceHole > 1 && lista[indiceHole - 1] < numerito)
                {
                    lista[indiceHole] = lista[indiceHole - 1];
                    indiceHole       -= 1;
                }
                //Le colocamos al agujero el dato correspondiente
                lista[indiceHole] = numerito;
            }
            //Mostrar lista ordenada
            Console.WriteLine("Lista Ordenada");
            lista.Transversa();
        }