Ordenamiento burbuja en c# introduciendo variables

Publicado: 19 abril, 2013 en Ayuda-al usuario
Etiquetas:, ,

// Este es el código que hace posible todo, tómalo cójalo el conocimiento humano le pertenece al mundo.

            Console.Title = «progarama de mack___Arreglos burbuja»;
            Console.ForegroundColor = ConsoleColor.Green;
            int n,i;
            Console.Write(«Introdusca el numero de numero que va a introducir :/> «);
            n = Convert.ToInt32(Console.ReadLine());
            Console.Clear();
            int[] arreglo = new int[n];
            for (i = 0; i < n; i++)
            {
                Console.Write(«# {0} numero: «, i);
                arreglo[i] = int.Parse(Console.ReadLine());
            }
            bubble_sort(arreglo);
            Console.WriteLine(«\n\nArreglo ordenado»);
            for ( i = 0; i < arreglo.Length; i++)
                Console.Write(arreglo[i] );
            Console.ReadKey();
        }
        static void bubble_sort(int[] arreglo)
        {
            int  i,j, temp;
            for (i = arreglo.Length – 1; i >= 0; i–)
            {
                for (j = 1; j <= i; j++)
                {
                    if (arreglo[j – 1] > arreglo[j])
                    {
                        temp = arreglo[j – 1];
                        arreglo[j – 1] = arreglo[j];
                        arreglo[j] = temp;
                    }
                }
            }

Deja un comentario