Nota: Esto lo hice por el metodo burbuja y tome de referencia esto que hice en una hoja de papel jaja:
Si posición 4 es mayor que posicion 4-1:
- Crear Variable que guarde posicion 3
- Posición 3 = posicion 4
- Posición 4 = posicion 3
Dentro de otro for:
Si posición 0 es menor que posicion 1
crear variable posicion 0.
-posicion 0 = posicion 1
-posicion 1 = posicion 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ejercicioMetodos
{
class Program
{
static void Main(string[] args)
{
numeroIngresar();
Console.ReadKey();
}
static void numeroIngresar()
{
int cont = 0;
int e = 0;
Console.WriteLine("Cuantos numeros quieres ingresar: ");
int numerosIngresar = int.Parse(Console.ReadLine());
int[] numeroArray = new int[numerosIngresar];
Random rnd1 = new Random();
int ordenar = numerosIngresar;
for (int i = 0; i < numerosIngresar; i++)
{
numeroArray[i] = rnd1.Next(5000);
}
while (e < numerosIngresar)
{
if (e + 1 >= numerosIngresar)
{
break;
}
if (numeroArray[e] < numeroArray[e + 1])
{
int auxiliar = numeroArray[e];
numeroArray[e] = numeroArray[e + 1];
numeroArray[e + 1] = auxiliar;
}
cont++;
if (cont == numerosIngresar)
{
break;
}
e++;
}
for (int i = 0; i < numerosIngresar; i++)
{
if (i == numerosIngresar - 1)
{
int contabilizar = i;
int x = 0;
double max = 9999999999999999999;
for (int j = contabilizar; j > 0; j--)
{
while (true )
{
if (j == 0)
{
j = i;
}
if (numeroArray[j] > numeroArray[j - 1])
{
int auxiliar = numeroArray[j];
numeroArray[j] = numeroArray[j - 1];
numeroArray[j - 1] = auxiliar;
}
x = x + 1;
if (x == 1000090)
{
break;
}
j--;
}
break;
}
}
}
for (int j = 0; j < numerosIngresar; j++)
{
Console.WriteLine(numeroArray[j]);
}
}
}
}