using System; using System.IO; using System.Runtime.CompilerServices; namespace ConsoleApp16 { internal class Program { static void Main(string[] args) { GenArray(100); } static int[] SortArray(int[] arr) { int len = arr.Length; for(int i=0;i<len-1;i++) { int temp1 = arr[i]; int temp2= arr[i+1]; if(temp1>temp2) { int temp = arr[i]; arr[i] = arr[i + 1]; arr[i+1] = temp; i = - 1; } } return arr; } static void GenArray(int len) { int[] arr = new int[len]; Random rnd = new Random(); for(int i=0;i<len;i++) { arr[i] = rnd.Next(0, Int32.MaxValue); } foreach(int i in arr) { Console.Write(i + "\t"); } Console.WriteLine("\n\n\nAfter sort:"); arr=SortArray(arr); foreach (int i in arr) { Console.Write(i + "\t"); } Console.WriteLine(); } } }
static int[] SortArray(int[] arr) { int len = arr.Length; for(int i=0;i<len-1;i++) { int temp1 = arr[i]; int temp2= arr[i+1]; if(temp1>temp2) { int temp = arr[i]; arr[i] = arr[i + 1]; arr[i+1] = temp; i = - 1; } } return arr; }
标签:sort,arr,temp,C#,System,len,int,static,array From: https://www.cnblogs.com/Fred1987/p/18053395