ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Método de inserción directa


Enviado por   •  12 de Octubre de 2015  •  Apuntes  •  4.947 Palabras (20 Páginas)  •  324 Visitas

Página 1 de 20

Método de inserción directa

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace PruebaVector

{

    class PruebaVector

    {

        private int[] vector;

        public void Cargar()

        {

            Console.WriteLine("Metodo de insercion directa");

            Console.Write("Cuantos longitud del vector:");

            string linea;

            linea = Console.ReadLine();

            int cant;

            cant = int.Parse(linea);

            vector = new int[cant];

            for (int f = 0; f < vector.Length; f++)

            {

                Console.Write("Ingrese elemento " + (f + 1) + ": ");

                linea = Console.ReadLine();

                vector[f] = int.Parse(linea);

            }

        }

        public void InsercionDirecta()

        {

            int auxili;

            int j;

            for (int i = 0; i < vector.Length; i++)

            {

                auxili = vector[i];

                j = i - 1;

                while (j >= 0 && vector[j] > auxili)

                {

                    vector[j + 1] = vector[j];

                    j--;

                }

                vector[j + 1] = auxili;

            }

        }

        public void Imprimir()

        {

            Console.WriteLine("Vector ordenados en forma ascendente");

            for (int f = 0; f < vector.Length; f++)

            {

                Console.Write(vector[f] + "  ");

            }

            Console.ReadKey();

        }

        static void Main(string[] args)

        {

            PruebaVector pv = new PruebaVector();

            pv.Cargar();

            pv.InsercionDirecta();

            pv.Imprimir();

        }

    }

}

Shell Sort

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace PruebaVector

{

    class PruebaVector

    {

        private int[] vector;

        public void Cargar()

        {

            Console.WriteLine("Metodo de Shell Sort");

            Console.Write("Cuantos longitud del vector:");

            string linea;

            linea = Console.ReadLine();

            int cant;

            cant = int.Parse(linea);

            vector = new int[cant];

            for (int f = 0; f < vector.Length; f++)

            {

                Console.Write("Ingrese elemento " + (f + 1) + ": ");

                linea = Console.ReadLine();

                vector[f] = int.Parse(linea);

            }

        }

        public void Shell()

        {

            int salto = 0;

            int sw = 0;

            int auxi = 0;

            int e = 0;

            salto = vector.Length / 2;

            while (salto > 0)

...

Descargar como (para miembros actualizados)  txt (11 Kb)   pdf (126.5 Kb)   docx (54.8 Kb)  
Leer 19 páginas más »
Disponible sólo en Clubensayos.com