public static void Test_OP_Radix_Sort(int seed, int n) { Console.WriteLine("\n Išorinėje atmintyje Radix rykiavimas\n"); Stopwatch watch = new Stopwatch(); MyIntArray myarray = new MyIntArray(n, seed); MyIntArray MySortedArray; Console.WriteLine("\n masyvas \n"); myarray.Print(n); watch.Start(); MySortedArray = (MyIntArray)RadixSort(myarray); watch.Stop(); var arrayTime = watch.Elapsed; Console.WriteLine("\n išrykiuotas \n"); MySortedArray.Print(n); MyIntList MySortedList; MyIntList mylist = new MyIntList(n, seed); //Console.WriteLine("\n sąrašas \n"); mylist.Print(n); watch.Start(); MySortedList = (MyIntList)RadixSort(mylist); watch.Stop(); var listTime = watch.Elapsed; Console.WriteLine("\n isrykiuotas \n"); MySortedList.Print(n); Console.WriteLine("array elapsed time: " + arrayTime + " list elapsed 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_OP_Radix_Sort_Comparison(int seed, int n) { Stopwatch watch = new Stopwatch(); MyIntArray myarray = new MyIntArray(n, seed); MyIntArray MySortedArray; watch.Start(); MySortedArray = (MyIntArray)RadixSort(myarray); watch.Stop(); var arrayTime = watch.Elapsed; MyIntList MySortedList; MyIntList mylist = new MyIntList(n, seed); watch.Start(); MySortedList = (MyIntList)RadixSort(mylist); watch.Stop(); var listTime = watch.Elapsed; Console.WriteLine("{0, -10} {1, -20} {2, -20}", n, arrayTime, listTime); }