Created
May 22, 2019 07:11
-
-
Save razpeitia/8bf5e892ac80a33eca3bf1337347b62e to your computer and use it in GitHub Desktop.
Tarea De @KIRAMOGAL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp2 | |
{ | |
class PruebaVector | |
{ | |
private int[] vector; | |
public void Cargar() | |
{ | |
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() | |
{ | |
Console.WriteLine("Ordenando con insersecion..."); | |
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 MetodoBurbuja() | |
{ | |
Console.WriteLine("Ordenando con burbuja..."); | |
int t; | |
for (int a = 1; a < vector.Length; a++) | |
for (int b = vector.Length - 1; b >= a; b--) | |
{ | |
if (vector[b - 1] > vector[b]) | |
{ | |
t = vector[b - 1]; | |
vector[b - 1] = vector[b]; | |
vector[b] = t; | |
} | |
} | |
} | |
public void Buscar() | |
{ | |
Console.WriteLine("Ingrese elemento que desea buscar en el arreglo: "); | |
int elemento = int.Parse(Console.ReadLine()); | |
string posicion = ""; | |
for (int i = 0; i < vector.Length; i++) | |
{ | |
if (vector[i] == elemento) | |
{ | |
posicion = posicion + ' ' + i; | |
} | |
} | |
if("".Equals(posicion)) | |
{ | |
Console.WriteLine("El elemento no se encuentra en el arreglo"); | |
} | |
else | |
{ | |
Console.WriteLine("El elemento se encuantra en las posiciones: " + posicion); | |
} | |
} | |
public void Imprimir() | |
{ | |
for (int f = 0; f < vector.Length; f++) | |
{ | |
Console.Write(vector[f] + " "); | |
} | |
Console.WriteLine(); | |
} | |
public void Esperar() | |
{ | |
Console.ReadKey(); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
PruebaVector pv = new PruebaVector(); | |
pv.Cargar(); | |
pv.Imprimir(); | |
pv.InsercionDirecta(); | |
pv.Imprimir(); | |
pv.MetodoBurbuja(); | |
pv.Imprimir(); | |
pv.Buscar(); | |
pv.Esperar(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment