using System; using System.IO; namespace Ordenacion1 { public class MetodoBurbuja { public static void Main(string[] args) { int[] vector; int temp; Console.Write("¿Cuántos números deseas ordenar? "); temp = Leer.datoInt(); vector = new int[temp]; for (int i = 0; i < temp; i++) { Console.Write("Introduce el dato " + (i+1) + " : "); vector[i] = Leer.datoInt(); } Console.Write("Vector a ordenar: [ "); for (int j = 0; j < vector.Length; j++) { Console.Write(vector[j] + " "); } Console.Write("]\n"); Burbuja(vector); Console.Write("Vector a ordenado: [ "); for (int j = 0; j < vector.Length; j++) { Console.Write(vector[j] + " "); } Console.Write("]\n"); Console.ReadKey(); } private static void Burbuja(int[] vector) { int temp, vueltas = 0; bool cambio; for (int i = 1; i <= vector.Length; i++) { cambio = false; vueltas++; for (int j = 0; j < vector.Length - i; j++) { if (vector[j] >= vector[j + 1]) { temp = vector[j + 1]; vector[j + 1] = vector[j]; vector[j] = temp; cambio = true; } } Console.Write("Vuelta " + (i) + " "); Console.Write("[ "); for (int k = 0; k < vector.Length; k++) { Console.Write(vector[k] + " "); } Console.Write("]\n"); if (cambio == false) break; } Console.WriteLine("Total Vueltas = " + vueltas); } } public class Leer { public static int datoInt() { string dato; dato = System.Console.ReadLine(); return int.Parse(dato); } } }