Bueno no me convence mucho la forma en que hice este código, quiero saber por algun experto si esta bien diseñado, es decir no se si existe una manera mas rapida o corta de hacerlo y me gustaría saberlo si ustedes alguna vez lo habéis echo mas corto, tambien pido porfavor que cualquier consejo que me lo digas, me encanta recibir criticas para mejorar y echarle mas ganas , Así que pido porfavor que mires el código no te cuesta nada y me harías mejorar con tu respuesta

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]);
            }
        }



    }
}
Se aprende viendo y aplicando Prueba, Error, Correccion
Lo acorte pero si se puede acortar mas, estaría dispuesto a escuchar vuestro consejo
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);

            }
            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]);
            }
        }



    }
}
Se aprende viendo y aplicando Prueba, Error, Correccion
Poco a poco! aun lo puedes recortar mucho mas.. lo que se me ocurre es esto.. primero recorro todo el array en busca de el numero mayor.. lo coloco en la primera posición y el que esta en la primera posición lo coloco donde estaba el numero mayor.. luego paso al segundo elemento del array busco desde el segundo elemento asta el final.. y repito la operación.. me explico como la mierda pero bueno.. te dejo el code para que lo veas mas claro..
using System;
using System.Collections.Generic;
using System.Text;


namespace OrdenarArray
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] listaNumeros = new int[15] { 3, 4, 5, 6, 22, 33, 22, 11, 23, 345, 4535, 123, 233, 34, 3 };

            int numeromayor = 0;

            for (int j = 0; j < 15; j++)
            {
                for (int e = j; e < 15; e++)
                {

                    if (listaNumeros[e] > numeromayor)
                    {
                        numeromayor = listaNumeros[e];

                        listaNumeros[e] = listaNumeros[j];

                        listaNumeros[j] = numeromayor;
                    }
                }

                Console.WriteLine(listaNumeros[j]);

                numeromayor = 0;
            }

            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Numeros ordenados correctamente");

            Console.ReadLine();

        }
Salud!
Responder

Volver a “VB/.NET”