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 DataIntList RadixSort(DataIntList data) { DataIntList[] buckets = new DataIntList[10]; if (data.GetType() == typeof(MyIntArray)) { for (int i = 0; i < buckets.Length; i++) { buckets[i] = new MyIntList(); } } else { for (int i = 0; i < buckets.Length; i++) { buckets[i] = new MyIntFileList(); } } for (int i = 0; i < data.LongestDigit; i++) { int first = data.First(); int digit = (int)((first % Math.Pow(10, i + 1)) / Math.Pow(10, i)); buckets[digit].Add(first); for (int j = 1; j < data.Length; j++) { int currnet = data.Next(); digit = (int)((currnet % Math.Pow(10, i + 1)) / Math.Pow(10, i)); buckets[digit].Add(currnet); } data.Clear(); for (int k = 0; k < 10; k++) { DataIntList bucket = buckets[k]; for (int l = 0; l < bucket.Length; l++) { if (l == 0) { data.Add(bucket.First()); } else { data.Add(bucket.Next()); } } buckets[k].Clear(); } } return(data); }
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); }