public static void Test_File_Radix_Sort(int seed, int n) { Console.WriteLine("\n VidinÄ—je atmintyje Radix rykiavimas\n"); string filename; Stopwatch watch = new Stopwatch(); filename = @"mydataarray.dat"; MyIntFileArray sortedFileArray; MyIntFileArray myFileArray = new MyIntFileArray(filename, n, seed); Console.WriteLine("\n FILE ARRAY \n"); myFileArray.Print(n); watch.Start(); sortedFileArray = (MyIntFileArray)RadixSort(myFileArray); watch.Stop(); var arrayTime = watch.Elapsed; Console.WriteLine("\n sorted FILE ARRAY \n"); sortedFileArray.Print(n); filename = @"mydatalist.dat"; MyIntFileList sortedFileList; MyIntFileList myfilelist = new MyIntFileList(filename, n, seed); Console.WriteLine("\n FILE LIST \n"); myfilelist.Print(n); watch.Start(); sortedFileList = (MyIntFileList)RadixSort(myfilelist); watch.Stop(); var listTime = watch.Elapsed; Console.WriteLine("\n SORTED FILE LIST \n"); sortedFileList.Print(n); Console.WriteLine("array elepsed time: " + arrayTime + " list elepsed time: " + listTime); }
public static void Test_File_Radix_Sort_Comparison(int seed, int n) { MyIntFileList MySortedList; MyIntFileList mylist = new MyIntFileList(@"testasList.dat", n, seed); Stopwatch watch = new Stopwatch(); Stopwatch watch2 = new Stopwatch(); MyIntFileArray myarray = new MyIntFileArray(@"testasArray.dat", n, seed); MyIntFileArray MySortedArray; watch.Start(); MySortedArray = (MyIntFileArray)RadixSort(myarray); watch.Stop(); var arrayTime = watch.Elapsed; watch2.Start(); MySortedList = (MyIntFileList)RadixSort(mylist); watch2.Stop(); var listTime = watch2.Elapsed; Console.WriteLine("{0, -10} {1, -20} {2, -20}", n, arrayTime, listTime); }
//-------------------------------------------------------- public static DataIntArray RadixSort(DataIntArray data) { DataIntArray[] buckets = new DataIntArray[10]; if (data.GetType() == typeof(MyIntArray)) { for (int i = 0; i < buckets.Length; i++) { buckets[i] = new MyIntArray(data.Length); } } else { for (int i = 0; i < buckets.Length; i++) { buckets[i] = new MyIntFileArray(data.Length); } } for (int i = 0; i < data.LongestDigit; i++) { for (int j = 0; j < data.Length; j++) { int digit = (int)((data[j] % Math.Pow(10, i + 1)) / Math.Pow(10, i)); buckets[digit].Add(data[j]); } int index = 0; for (int k = 0; k < 10; k++) { DataIntArray bucket = buckets[k]; for (int l = 0; l < bucket.Length; l++) { data[index++] = bucket[l]; } buckets[k].Clear(); } } return(data); }