using System;
namespace Practica2Tema3
{
public class Practica2Tema3
{
// Vamos a ingresar lista
public static string[] IngresaDatos()
{
string[] arreglo = new string[5]; // 5 elementos
Console.WriteLine("Ingresame 5 nombres al azar:");
for (int i = 0; i < arreglo.Length; i++)
{
Console.Write("Nombre ingresado ---> #" + (i + 1) + " : ");
arreglo[i] = Console.ReadLine();
}
return arreglo;
}
// Aquí burbujita Ascendido
public static void BubbleAsc(string[] arreglo)
{
int n = arreglo.Length;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (string.Compare(arreglo[j], arreglo[j + 1], StringComparison.OrdinalIgnoreCase) > 0)
{
string temp = arreglo[j];
arreglo[j] = arreglo[j + 1];
arreglo[j + 1] = temp;
}
}
}
}
// Y burbujita Descendido
public static void BubbleDesc(string[] arreglo)
{
int n = arreglo.Length;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (string.Compare(arreglo[j], arreglo[j + 1], StringComparison.OrdinalIgnoreCase) < 0)
{
string temp = arreglo[j];
arreglo[j] = arreglo[j + 1];
arreglo[j + 1] = temp;
}
}
}
}
// Lista Creada
public static void MostrarArreglo(string[] arreglo, string mensaje)
{
Console.WriteLine(mensaje);
foreach (string nombre in arreglo)
{
Console.Write(nombre + " >>> ");
}
Console.WriteLine();
}
// Funciones
public static void Main(string[] args)
{
string[] datos = IngresaDatos(); // Crear Lista
// Ascendido
BubbleAsc(datos);
MostrarArreglo(datos, "\nLista ordenada ascendentemente:");
// Descendido
BubbleDesc(datos);
MostrarArreglo(datos, "\nLista ordenada descendentemente:");
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: