Você está na página 1de 25

alumno :diego montaño quispe

carrera:ing.sis

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace menu

class Program

//ZONA GLOBAL

int[] edad;

int tam;

public void menu()

Console.WriteLine("1.insertar");

Console.WriteLine("2.listar ");

Console.WriteLine("3.modificar");

Console.WriteLine("4.eliminar");

Console.WriteLine("5.metodos de ordenamiento(asc,desc)");

Console.WriteLine("6.salir");

Console.WriteLine("elija opcion------>");
}

public void menuinsertar()

Console.WriteLine(" Menu insertar");

Console.WriteLine("1.por posicio");

Console.WriteLine("2.global(aleatorio)");

Console.WriteLine("3.retornar");

public void insertar()

Console.WriteLine("INGRESE TAMAÑO");

tam = Convert.ToInt32(Console.ReadLine());

//dimensionando vector

edad = new int[tam];

//for (int i = 0; i < tam; i++)

Console.WriteLine("Introduzca valores del vector");

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

Console.Write(" edad[" + i + "]=");

edad[i] = Convert.ToInt32(Console.ReadLine());

public void listar()

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

{
Console.Write("{0}\t", edad[i]);

public void insertGlobal()

int limInf, limSup;

Console.WriteLine("dimension del vectro");

tam = Convert.ToInt32(Console.ReadLine());

edad = new int[tam];

Console.Write("introduxca limite inferior");

limInf = Convert.ToInt32(Console.ReadLine());

Console.Write("INTRODUZCA limite superior");

limSup = Convert.ToInt32(Console.ReadLine());

Random rnd = new Random();

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

edad[i] = rnd.Next(limInf, limSup + 1);

public void modificar()

Console.WriteLine("MENU MODIFICAR");

Console.WriteLine("1.Por posicion");

Console.WriteLine("2.global");

Console.WriteLine("3.elija opcion");

public void Ascendenteburbuja()


{

int aux;

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

for (int j = 0; j < edad.Length - 1; j++)

if (edad[j] > edad[j + 1])

aux = edad[j];

edad[j] = edad[j + 1];

edad[j + 1] = aux;

listar();

public void Descendenteburbuja()

int aux;

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

for (int j = 0; j < edad.Length - 1; j++)

if (edad[j] < edad[j + 1])

aux = edad[j];

edad[j] = edad[j + 1];


edad[j + 1] = aux;

listar();

public void eliminar()

Console.Clear();

public void menuordenar()

Console.WriteLine("Menu Ordenar");

Console.WriteLine("1.burbuja ");

Console.WriteLine("2.seleccion ");

Console.WriteLine("3.insercion");

Console.WriteLine("4.shell short");

Console.WriteLine("5.quick short");

Console.WriteLine("6.retornar");

Console.Write("elija una opcion -----> ");

public void menuseleccion()

Console.WriteLine("1.ascendente");

Console.WriteLine("2.descendente");

public void menuburbuja()


{

Console.WriteLine("1.ascendente");

Console.WriteLine("2.descendente");

public void menuinsercion()

Console.WriteLine("1.ascendente");

Console.WriteLine("2.descendente");

public void menushell()

Console.WriteLine("1.ascendente");

Console.WriteLine("2.descendente");

public void menuquick()

Console.WriteLine("1.ascendente");

Console.WriteLine("2.descendente");

public void ascenseleccion()

int aux, p;

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

aux = edad[i];

p = i;
for (int j = i + 1; j < edad.Length; j++)

if (edad[j] < aux)

aux = edad[j];

p = j;

edad[p] = edad[i];

edad[i] = aux;

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

Console.Write(edad[i] + "\t");

Console.ReadKey();

public void descenseleccion()

{
int aux, p;

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

aux = edad[i];

p = i;

for (int j = i + 1; j < edad.Length; j++)

if (edad[j] > aux)

aux = edad[j];

p = j;

edad[p] = edad[i];

edad[i] = aux;

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

Console.Write(edad[i] + "\t");

Console.ReadKey();

}
public void incersiondirecta1()

int aux, j;

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

aux = edad[i];

j = i - 1;

while (j >= 0 && edad[j] > aux)

edad[j + 1] = edad[j];

j--;

edad[j + 1] = aux;

public void imprimir1()

Console.WriteLine("descendente");

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

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

Console.ReadKey();

}
public void incersiondirecta()

int aux, j;

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

aux = edad[i];

j = i - 1;

while (j >= 0 && edad[j] < aux)

edad[j + 1] = edad[j];

j--;

edad[j + 1] = aux;

public void imprimir()

Console.WriteLine("ascendente");

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

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

Console.ReadKey();

private int[] vector3;

public void ascendshell()


{

Console.Write("longitud del vector");

int cant;

cant = int.Parse(Console.ReadLine());

vector3 = new int[cant];

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

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

vector3[f] = int.Parse(Console.ReadLine());

public void Shell()

int salto = 0;

int sw = 0;

int auxi=0;

int e=0;

salto = vector3.Length / 2;

while (salto > 0)

sw = 1;

while (sw != 0)

sw = 0;

e = 1;

while (e <= (vector3.Length - salto))


{

if (vector3[e - 1] > vector3[(e - 1) + salto])

auxi = vector3[(e - 1) + salto];

vector3[(e - 1) + salto] = vector3[e - 1];

vector3[(e - 1)] = auxi;

sw = 1;

e++;

salto = salto / 2;

public void imprimir2()

Console.Write("vector en forma ascendente");

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

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

Console.ReadKey();

public void descenshell()

public void ascendquick()


{

int n;

Console.WriteLine("longitud");

n = Int32.Parse(Console.ReadLine());

class llenar

int h;

int[] vector;

public llenar(int n)

h = n;

vector = new int[h];

for (int i = 0; i < h; i++)

Console.Write("ingrese valor{0}:", i + 1);

vector[i] = Int32.Parse(Console.ReadLine());

llenar b = new llenar(n);

quicksort(vector, 0, h - 1);

mostrar();

public void quicksort(int[] vector, int primero, int ultimo)

{
int i, j, central;

double pivote;

central = (primero + ultimo) / 2;

pivote = vector[central];

i = primero;

j = ultimo;

do

while (vector[i] < pivote)

i++;

while (vector[j] > pivote)

j--;

if (i <= j)

int temp;

temp = vector[i];

vector[i] = vector[j];

vector[j] = temp;

j++;

j--;

while (i <= j);

if (primero < j)

quicksort(vector, primero, j);

}
if (i < ultimo)

quicksort(vector, i, ultimo);

public void mostrar()

Console.WriteLine("ASCENDENTE");

for (int i = 0; i < h; i++)

Console.Write("{0}", vector[i]);

Console.ReadLine();

public void descendquick()

static void Main(string[] args)

int op = 0, op1 = 0, op5 = 0, op6 = 0, op7 = 0, op8 = 0, op9 = 0, op10 = 0;

Program p = new Program();

do

p.menu();
op = Convert.ToInt32(Console.ReadLine());

Console.Clear();

switch (op)

case 1:

do

p.menuinsertar();

Console.Write("ELIJA OPCION");

op1 = Convert.ToInt32(Console.ReadLine());

Console.Clear();

switch (op1)

case 1:

p.insertar();

break;

case 2:

p.insertGlobal();

break;

case 3:

break;
default:

Console.WriteLine("opcion no valida");

break;

} while (op1 != 3);

//p.insertar();

break;

case 2:

p.listar();

break;

case 3:

p.modificar();

break;

case 4:

p.eliminar();

break;

case 5:
{

p.menuordenar();

Console.Write("Elija opcion");

op5 = Convert.ToInt32(Console.ReadLine());

Console.Clear();

switch (op5)

case 1:

do

p.menuburbuja();

Console.WriteLine("ELIJA OPCION--->");

op6 =
Convert.ToInt32(Console.ReadLine());

Console.Clear();

switch (op6)

case 1:

p.Ascendenteburbuja();

break;

case 2:

p.Descendenteburbuja();

break;
}

case 3:

default:

Console.WriteLine("OPCION NO
VALIDA");

break;

while (op6 != 3);

p.menu();

break;

case 2:

do

p.menuseleccion();

Console.WriteLine("ELIJA OPCION--->");

op7 = Convert.ToInt32(Console.ReadLine());

Console.Clear();

switch (op7)

{
case 1:

p.ascenseleccion();

break;

case 2:

p.descenseleccion();

break;

case 3:

default:

Console.WriteLine("OPCION NO
VALIDA ");

break;

while (op7 != 3);

p.menu();

break;

case 3:

do
{

p.menuinsercion();

Console.WriteLine("ELIJA OPCION--->");

op8 = Convert.ToInt32(Console.ReadLine());

Console.Clear();

switch (op8)

case 1:

p.incersiondirecta1();

p.imprimir();

break;

case 2:

p.incersiondirecta();

p.imprimir1();

break;

case 3:

default:

Console.WriteLine("OPCION NO
VALIDA ");

break;

}
}

while (op8 != 3);

p.menu();

break;

case 4:

do

p.menushell();

Console.WriteLine("ELIJA OPCION--->");

op9 = Convert.ToInt32(Console.ReadLine());

Console.Clear();

switch (op9)

case 1:

p.ascendshell();

p.Shell();

p.imprimir2();

break;

case 2:

break;

}
case 3:

default:

Console.WriteLine("OPCION NO
VALIDA ");

break;

while (op9 != 3);

p.menu();

break;

case 5:

do

p.menuquick();

Console.WriteLine("ELIJA OPCION--->");

op10 = Convert.ToInt32(Console.ReadLine());

Console.Clear();

switch (op10)

case 1:

p.ascendquick();

break;
}

case 2:

break;

case 3:

default:

Console.WriteLine("OPCION NO
VALIDA ");

break;

while (op10 != 3);

p.menu();

break;

break;

case 6:

default:

Console.WriteLine("OPCION NO VALIDA");

break;

}
}

} while (op != 6);

Você também pode gostar