static void Main(string[] args) { int[] array = { 2, 1, 101, 187, 198 }; MergeSort sort = new MergeSort(); sort.Sort(ref array, 0, array.Length - 1); foreach (var item in array) { Console.Write(item + " "); } Console.ReadLine(); }
static void Main(string[] args) { int[] bubble = { 4, 8, 1, 11, 5, 3, 2, 10 }; Sort.BubbbleSort(bubble); foreach (var item in bubble) { Console.Write($"{item} "); } Console.WriteLine(); int[] selection = { 4, 8, 1, 11, 5, 3, 2, 10 }; Sort.SelectionSort(selection); foreach (var item in selection) { Console.Write($"{item} "); } Console.WriteLine(); int[] insert = { 4, 8, 1, 11, 5, 3, 2, 10 }; Sort.InsertSort(insert); foreach (var item in insert) { Console.Write($"{item} "); } Console.WriteLine(); int[] merge = { 4, 8, 1, 11, 5, 3, 2, 10 }; MergeSort.Sort(merge, 0, merge.Length - 1); foreach (var item in merge) { Console.Write($"{item} "); } Console.WriteLine(); int[] quick = { 8, 8, 8, 4, 11, 9, 3 }; QuickSort.Sort(quick, 0, quick.Length - 1); foreach (var item in quick) { Console.Write($"{item} "); } Console.WriteLine(); }
public static void Main(string[] args) { Console.WriteLine("Insertion sort"); var array = new int[] { 6, 5, 3, 1, 8, 7, 2, 4, 6, 6 }; InsertionSort.Sort(array); Console.WriteLine("Quick sort"); array = new int[] { 6, 5, 3, 1, 8, 7, 2, 4 }; QuickSort.Sort(array, 0, array.Length - 1); Print(array); Console.WriteLine("Merge sort"); array = new int[] { 6, 5, 3, 1, 8, 7, 2, 4 }; var result = MergeSort.Sort(array); Print(result); }
static void Main2(string[] args) { Bicycle[] bicycles = new Bicycle[3]; bicycles[0] = new Bicycle("Steven's Bicycles", System.Drawing.Color.Green, "This is a feisty bike with a bit of zest", 4.9); bicycles[1] = new Bicycle("bike two", System.Drawing.Color.Red, "This is a cute bike", 3.2); bicycles[2] = new Bicycle("Another bike", System.Drawing.Color.Turquoise, "Bikey McBike Face", 13.8); BubbleSort.Sort(bicycles); Bicycle.PrintBicycles(bicycles); int[] integers = new int[] { 1, 2, 3, 18, 32, 55, 34, 89, 15, 23, 41, 6, 18, 23 }; //int[] integers = new int[] { 4, 18, 11, 7, 13, 6, 3, 1, 9 }; BubbleSort.Sort(integers); //MergeSort.InArraySort(integers); Console.WriteLine(BinarySearch.Search(integers, 89)); //SelectionSort.Sort(integers); foreach (int i in integers) { Console.Write(i + " "); } Console.WriteLine(); string[] strings = new string[] { "als", "ik", "boven", "op", "de", "dom", "sta", "kijk", "ik" }; MergeSort.Sort(strings); //SelectionSort.Sort(strings); foreach (string s in strings) { Console.Write(s + " "); } Console.WriteLine(); int[] AddedNumber = BinaryAddition.Add(new int[] { 1, 0, 0, 1, 0, 1 }, new int[] { 1, 1, 0, 0, 1, 1 }); foreach (int i in AddedNumber) { Console.Write(i + " "); } Console.WriteLine(); LinearSearch ls = new LinearSearch(); ls.Search(); InsertionSort.InsertionSortConsoleProgram(); }
static void Main(string[] args) { Console.Write("Enter size : "); int size = int.Parse(Console.ReadLine()); // Generate array with random elements int[] arr = Generator(size); // Array for sorting int[] changedArr = new int[arr.Length]; // Array for calculating time TimeSpan[] delta = new TimeSpan[5]; Print(arr); Console.Write("Select which algorithm you want to perform :\n1-Insertion sort\n" + "2-Bubble sort\n3-Quicksort\n4-Heap sort\n5-Merge sort\n6-All\nEnter number(s) : "); string n = Console.ReadLine(); string[] num; // Exploration of input string if (n.Contains(',')) { num = n.Split(','); } else if (n.Contains('-')) { num = new string[int.Parse((n[n.Length - 1]).ToString()) - int.Parse(n[0].ToString()) + 1]; int t = 0; for (int i = int.Parse(n[0].ToString()); i <= int.Parse((n[n.Length - 1]).ToString()); i++) { num[t++] = i.ToString(); } } else { num = new string[] { n } }; // Call needed function or functions for (int i = 0; i < num.Length; i++) { switch (num[i]) { case "1": changedArr = InsertionSort.Sort(arr); Print(changedArr); Console.WriteLine("Memory = " + InsertionSort.MemoryAllocation() + " byte"); break; case "2": changedArr = BubbleSort.Sort(arr); Print(changedArr); Console.WriteLine("Memory = " + BubbleSort.MemoryAllocation() + " byte"); break; case "3": changedArr = QuickSort.Sort(arr); Print(changedArr); Console.WriteLine("Memory = " + QuickSort.MemoryAllocation() + " byte"); break; case "4": changedArr = HeapSort.Sort(arr); Print(changedArr); Console.WriteLine("Memory = " + HeapSort.MemoryAllocation() + " byte"); break; case "5": changedArr = MergeSort.Sort(arr); Print(changedArr); Console.WriteLine("Memory = " + MergeSort.MemoryAllocation() + " byte"); break; case "6": DateTime inT1 = DateTime.Now; changedArr = InsertionSort.Sort(arr); Print(changedArr); DateTime inT2 = DateTime.Now; delta[0] = inT2 - inT1; Console.WriteLine("Memory = " + InsertionSort.MemoryAllocation() + " byte"); DateTime buT1 = DateTime.Now; changedArr = BubbleSort.Sort(arr); Print(changedArr); DateTime buT2 = DateTime.Now; delta[1] = buT2 - buT1; Console.WriteLine("Memory = " + BubbleSort.MemoryAllocation() + " byte"); DateTime quT1 = DateTime.Now; changedArr = QuickSort.Sort(arr); Print(changedArr); DateTime quT2 = DateTime.Now; delta[2] = quT2 - quT1; Console.WriteLine("Memory = " + QuickSort.MemoryAllocation() + " byte"); DateTime heT1 = DateTime.Now; changedArr = HeapSort.Sort(arr); Print(changedArr); DateTime heT2 = DateTime.Now; delta[3] = heT2 - heT1; Console.WriteLine("Memory = " + HeapSort.MemoryAllocation() + " byte"); DateTime meT1 = DateTime.Now; changedArr = MergeSort.Sort(arr); Print(changedArr); DateTime meT2 = DateTime.Now; delta[4] = meT2 - meT1; Console.WriteLine("Memory = " + MergeSort.MemoryAllocation() + " byte"); for (int j = 0; j < delta.Length; j++) { if (delta[j] == delta.Min()) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(delta[j]); Console.ResetColor(); } else { Console.WriteLine(delta[j]); } } break; default: Console.WriteLine("Incorrect number!"); break; } } }
static void RunMergeSort() { Console.WriteLine("Mergesort"); Char[] arr = chars.ToArray(); OutputCharArray(arr, "Input"); MergeSort<Char> ms = new MergeSort<char>(); ms.Sort(ref arr); OutputCharArray(arr, "Output"); Int64[] arri = ints.ToArray(); OutputIntArray(arri, "Input"); MergeSort<Int64> msi = new MergeSort<Int64>(); msi.Sort(ref arri); OutputIntArray(arri, "Output"); }