using System;
namespace EvaluacionUnidad2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("========================================");
Console.WriteLine(" EVALUACIÓN UNIDAD 2");
Console.WriteLine("========================================");
Console.WriteLine("Keyla Ester Alvarez Ochoa - 20211031014");
Console.WriteLine("Danny Dariel Ayala Rosales - 20221000027");
Console.WriteLine();
int[] datos = { 8, 3, 10, 1, 7, 2, 9, 4, 6, 5 };
MostrarArray("Array Original", datos);
// Copias del arreglo
int[] burbuja = (int[])datos.Clone();
int[] seleccion = (int[])datos.Clone();
// Método Burbuja
Burbuja(burbuja);
MostrarArray("Ordenado con Burbuja", burbuja);
// Método Selección
Seleccion(seleccion);
MostrarArray("Ordenado con Selección", seleccion);
Console.WriteLine();
Console.Write("Ingrese el número que desea buscar: ");
int clave = Convert.ToInt32(Console.ReadLine());
int posicion = BusquedaBinaria(burbuja, clave);
if (posicion != -1)
{
Console.WriteLine("Número encontrado en el índice: " + posicion);
}
else
{
Console.WriteLine("Número no encontrado.");
}
Console.WriteLine();
Console.WriteLine("Presione cualquier tecla para salir...");
Console.ReadKey();
}
// Mostrar arreglo
static void MostrarArray(string titulo, int[] datos)
{
Console.WriteLine(titulo + ":");
for (int i = 0; i < datos.Length; i++)
{
Console.Write(datos[i]);
if (i < datos.Length - 1)
Console.Write(", ");
}
Console.WriteLine();
Console.WriteLine();
}
// Método Burbuja
static void Burbuja(int[] datos)
{
for (int i = 0; i < datos.Length - 1; i++)
{
for (int j = 0; j < datos.Length - i - 1; j++)
{
if (datos[j] > datos[j + 1])
{
int aux = datos[j];
datos[j] = datos[j + 1];
datos[j + 1] = aux;
}
}
}
}
// Método Selección
static void Seleccion(int[] datos)
{
for (int i = 0; i < datos.Length - 1; i++)
{
int minimo = i;
for (int j = i + 1; j < datos.Length; j++)
{
if (datos[j] < datos[minimo])
{
minimo = j;
}
}
int aux = datos[i];
datos[i] = datos[minimo];
datos[minimo] = aux;
}
}
// Búsqueda Binaria
static int BusquedaBinaria(int[] datos, int clave)
{
int izquierda = 0;
int derecha = datos.Length - 1;
while (izquierda <= derecha)
{
int mitad = (izquierda + derecha) / 2;
if (datos[mitad] == clave)
return mitad;
if (clave < datos[mitad])
derecha = mitad - 1;
else
izquierda = mitad + 1;
}
return -1;
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: