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 void TestMyIntArray() { int[] items = new int[6] { 2, 4, 6, 8, 10, 12 }; MyIntArray myIntArray = new MyIntArray(items); //Now we can use foreach to iterate through the array foreach (int i in myIntArray) { Assert.IsTrue(i % 2 == 0); Assert.IsTrue(i > 0); Assert.IsTrue(i <= 12); } }
static void Main(string[] args) { IArray arr = new MyIntArray(5); for (int i = 0; i < 5; i++) { arr.Update(i, i); } arr.Print(); Console.WriteLine(arr.Find(3)); arr.Add(100); arr.Print(); arr.Remove(3); arr.Print(); }
static void Main(string[] args) { // Luodaan MyIntArray-olio MyIntArray mia = new MyIntArray(); // Asetetaan ominaisuudelle Array1 arvo int[] arr1 = { 7, 1, 4 }; mia.Array1 = arr1; // Kutsutaan Write-metodia mia.Write(", "); // T33. Jos WriteStatic on staattinen // MyIntArray.WriteStatic(arr1, ", "); // Vertaa taulukon lajittelumetodi Array.Sort(arr1); // T34. Luo Dice -olio ja anna arvo ominaisuudelle Ran }
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); }
//-------------------------------------------------------- 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); }