Вы находитесь на странице: 1из 5

using System;

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

namespace Semana1
{
class tarea1
{
private int[] v1;
private int a;

//Aqui se ingresa la longitud del vector


public void longv1()
{
Console.WriteLine("Ingresa la longitud del Vector");
a = Convert.ToInt32(Console.ReadLine());
v1=new int[a];
}

//Aqui se insertan los valores del vector


public void insvv1()
{
for (int i = 0; i < a; i++)
{
Console.WriteLine("Ingrese Valor en la posicion " + (i+1) + ":");
v1[i] = Convert.ToInt32(Console.ReadLine());
}
}

//Aqui hace el ordenamiento por el Metodo Burbuja


public void ordv1()
{
int temp;
for (int x = 1; x < a; x++)
for (int j = a-1;j>=x; j--)
{
if (v1[j-1] > v1[j])
{
temp = v1[j-1];
v1[j-1] = v1[j];
v1[j] = temp;
}
}
}

//Aqui se imprime los valores ordenados del vector


public void impv1()
{
Console.WriteLine("Ordenados de forma Ascendente");
for (int i = 0; i < a; i++)
{
Console.Write(v1[i] + " ");
}
Console.ReadKey();
}

//Aqui iniciamos la busqueda del valor


public void busv1()

{
int b1,ma;
int mi = 0, r=0;
ma = a;
bool enc = false;
Console.WriteLine("Valor a buscar:");
b1 = Convert.ToInt32(Console.ReadLine());
while (mi <= ma && enc == false)
{
r = (mi + ma) / 2;
if (v1[r] == b1)
enc = true;
if (v1[r] > b1)
ma = r - 1;
else
mi = r + 1;
}
if (enc == false)
{
Console.WriteLine("El valor {0} no fue encontrada", b1);
}
else
{
Console.WriteLine("El valor {0} esta en la posicion: {1}", b1, r + 1);
}
Console.ReadKey();
}

static void Main(string[] args)


{

tarea1 t1 = new tarea1();


int opc1;
do
{
int opc2;
do
{
Console.Clear();
Console.WriteLine("Programa creado por Jorge Luis Mondragn");
Console.Write("Seleccione una opcion:\n\t1.-Insertar tamao del
vector.\n\t2.-Insertar valores en el vector.\n\t3.-Ordenar los valores.\n\t4.Buscar valor.\n\t5.-Salir.\n\t");
opc2 = Convert.ToInt32(Console.ReadLine());
switch (opc2)
{
case 1:
Console.Clear();
t1.longv1();
break;
case 2:
Console.Clear();
t1.insvv1();
break;
case 3:
Console.Clear();
t1.ordv1();
t1.impv1();
break;
case 4:
Console.Clear();

t1.busv1();
break;
default:
break;
}
}
while (opc2 < 5);
Console.Clear();
Console.Write("Desea dar otro vector:\n\t1.-Si\n\t2.-No\n\t");
opc1 = Convert.ToInt32(Console.ReadLine());
}
while (opc1 < 2);
}
}
}

Вам также может понравиться