int [] 100000に乱数つっこんで選択ソートかけた比較 9734 ミリ秒 v1.14/noOptimiz Visual C# .NET Compiler version 7.10.3052.4 9437 ミリ秒 v1.14/optimiz Visual C# .NET Compiler version 7.10.3052.4 20219 ミリ秒 v2.0.40607 VS2005β←ゴミ
『ソース』 using System; public class SS{ public static void Main(){ int i; int MAX=100000; int [] ai=new int [MAX]; Random rd=new Random(); for(i=0;i<MAX;i++){ ai[i]=rd.Next(); } for(i=0;i<MAX;i+=1000){ Console.WriteLine("{0}",ai[i]); } int ET2; int ET1=Environment.TickCount; Console.WriteLine("Pre: {0} mil second", ET1); selectsort(ai); ET2=Environment.TickCount; Console.WriteLine("After: {0} mil second", ET2); Console.WriteLine("---------------\n"); for(i=0;i<MAX;i+=1000){ Console.WriteLine("{0}",ai[i]); } Console.WriteLine("WORK {0} /ms",ET2-ET1); }
public static void selectsort(int [] a) { int i,j,k; int min; for(i=0;i<a.Length-1;i++) { min = a[i];k=i; for(j=i+1;j<a.Length;j++) if(a[j] < min){min = a[j];k=j;} a[k]=a[i];a[i]=min; } }