C#输入排序-冒泡
1 using System.Collections.Generic; 2 using System.Linq; 3 using System.Text; 4 namespace MP 5 { 6 class Pro 7 { 8 public void f(int n) 9 { 10 int[] a = new int[n]; 11 int i = 0, temp, j = 0; 12 for (i = 0; i < n; i++) 13 { 14 a[i] = Int32.Parse(Console.ReadLine()); 15 16 if(i==n-1) 17 18 { 19 Console.WriteLine("start:"); 20 break; 21 } 22 } 23 for (i = 0; i < a.Length - 1; i++) 24 { 25 for (j = 0; j < a.Length - i - 1; j++) 26 { 27 if (a[j] > a[j + 1]) 28 { 29 temp = a[j]; 30 a[j] = a[j + 1]; 31 a[j + 1] = temp; 32 } 33 } 34 } 35 for (i = 0; i < a.Length; i++) 36 { 37 Console.WriteLine(a[i]); 38 } 39 } 40 static void Main(string[] args) 41 { 42 Pro p = new Pro(); 43 int k = Int32.Parse(Console.ReadLine()); 44 p.f(k); 45 Console.ReadKey(); 46 } 47 } 48 }