You are on page 1of 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace algoritmo
{
class ordenamiento
{

private int[] lista;


public void Cargar()
{
Console.Write("Cuantos longitud del vector:");
string linea;
linea = Console.ReadLine();
int cant;
cant = int.Parse(linea);
lista = new int[cant];
for (int f = 0; f < lista.Length; f++)
{
Console.Write("Ingrese elemento " + (f) + ": ");
linea = Console.ReadLine();
lista[f] = int.Parse(linea);
}
}
public void InsercionDirecta()
{
int auxili;
int j;
for (int i = 0; i < lista.Length; i++)
{
auxili = lista[i];
j = i - 1;
while (j >= 0 && lista[j] > auxili)
{
lista[j + 1] = lista[j];
j--;
}
lista[j + 1] = auxili;
}
}
public void Imprimir()
{
Console.WriteLine("Vector ordenados ");

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


{
Console.Write(lista[f] +("````") );

Console.ReadLine();

}
public void buscar()
{

int aux = 0;
Console.Write("ingrese un numero buscar: ");
int buscarN = int.Parse(Console.ReadLine());
for (int i = 0; i < lista.Length;i++ )
{
if(lista[i]==buscarN){
Console.WriteLine(" numero: "+buscarN);
Console.WriteLine(" posicion: " + i);
aux = 1;
break;

}
}
//validar si existe un numero
if(aux==0){
Console.WriteLine("no se encontro el numero...");
}
Console.ReadLine();
}

}
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace algoritmo
{
class Program
{
static void Main(string[] args)
{
ordenamiento objeto1 = new ordenamiento();
objeto1.Cargar();
objeto1.InsercionDirecta();
objeto1.Imprimir();
Console.WriteLine("//////////////////////////");
objeto1.buscar();
}
}
}

You might also like