static void Main(string[] args) { int[] OriginalArray = { 5, 89, 43, 13, 67, 11, 45 }; int[] A = new int[OriginalArray.Length]; SortingAlgorithms sortAlgo = new SortingAlgorithms(); // insertion sort demo Array.Copy(OriginalArray, A, A.Length); sortAlgo.InsertionSort(A); Console.WriteLine("After insertion sort list contains: "); foreach (var item in A) Console.Write(" {0}", item); Console.WriteLine(); // Selection sort demo Array.Copy(OriginalArray, A, A.Length); sortAlgo.SelectionSort(A); Console.WriteLine("After Selection sort list contains: "); foreach (var item in A) Console.Write(" {0}", item); Console.WriteLine(); // Bubble sort demo Array.Copy(OriginalArray, A, A.Length); sortAlgo.BubbleSort(A); Console.WriteLine("After Bubble sort list contains: "); foreach (var item in A) Console.Write(" {0}", item); Console.WriteLine(); }
public void Test_AddInterval() { Interval[] empty = new Interval[] { }; Interval[] result; SortingAlgorithms algo = new SortingAlgorithms(); result = algo.AddInterval(empty, new Interval { start = 0, end = 2 } ); Assert.AreEqual(1, result.Length); result = algo.AddInterval(result, new Interval { start = 3, end = 5 } ); Assert.AreEqual(2, result.Length); result = algo.AddInterval(result, new Interval { start = 4, end = 6 } ); Assert.AreEqual(2, result.Length); result = algo.AddInterval(result, new Interval { start = 1, end = 4 } ); Assert.AreEqual(1, result.Length); }
static void Main(string[] args) { int[] ints = new int[] { 3, 5, 8, 10, 12, 55, 88, 76, 33, 44, 55, 88, 358, 67}; double[] doubles = new double[] { 33.55, 3.2, 12.578, 1241234.4456, 1.8, 55.6, 77.99565, 1.776, 333, 88}; string[] strings = new string[] { "asd", "dfg", "wersvs", "ertgvsdv456", "adf435", "dfsghti", "poiuyHJK"}; SortingAlgorithms<int> intTest = new SortingAlgorithms<int>(ints); intTest.Process(); SortingAlgorithms<double> doubleTest = new SortingAlgorithms<double>(doubles); doubleTest.Process(); SortingAlgorithms<string> stringTest = new SortingAlgorithms<string>(strings); stringTest.Process(); }
public void Test_ScheduledEvents() { Interval[] events1 = new Interval[] { new Interval() { start = 1, end = 4 }, new Interval() { start = 12, end = 15 }, new Interval() { start = 5, end = 8 }, new Interval() { start = 9, end = 10 }, new Interval() { start = 2, end = 7 }, new Interval() { start = 9, end = 11 }, }; SortingAlgorithms algo = new SortingAlgorithms(); List < Interval > listEvents = new List<Interval>(events1); Assert.AreEqual(2, algo.MaxScheduledEvents(listEvents)); listEvents.Add( new Interval() { start = 6, end = 11 } ); Assert.AreEqual(3, algo.MaxScheduledEvents(listEvents)); }
public void Init() { arr = new int[1000000]; rnd = new Random(); sorter = new SortingAlgorithms(); }
public void Setup() { _algo = new SortingAlgorithms(); _intArray = new int[] { 2, 89, 350, 1, 25, 44, 120, 89, 55, 500, 20}; }
public static void Main(string[] args) { CreateHeader(); while (true) { Console.WriteLine("Input problem #:"); string userInput = "lis"; int problemNumber = 0; if (userInput == "sort") { SortingAlgorithms SortingAlgorithms = new SortingAlgorithms(); SortingAlgorithms.Main(); } else if (userInput == "LinkedList") { LinkedListTest linkedList = new LinkedListTest(); linkedList.Main(); } else if (userInput == "Fib") { Fib fib = new Fib(); fib.Main(); } else if (userInput == "lis") { LISS lis = new LISS(); lis.Main(); } else if (userInput == "search") { SearchingAlgorithms search = new SearchingAlgorithms(); search.Main(); } else { bool validInput = Int32.TryParse(userInput, out problemNumber); if (validInput) { switch (problemNumber) { case 1: Problem1 problem1 = new Problem1(); problem1.Main(); break; case 21: Problem21 problem21 = new Problem21(); problem21.Main(); break; case 29: Problem29 problem29 = new Problem29(); problem29.Main(); break; case 37: Problem37 problem37 = new Problem37(); problem37.Main(); break; case 44: Problem44 problem44 = new Problem44(); problem44.Main(); break; case 57: Problem57 problem57 = new Problem57(); problem57.Main(); break; default: break; } } } } }
public Diagnostics() { // constructor creates objects for sorting and for searching sortObject = new SortingAlgorithms(); searchObject = new SearchAlgorithms(); }
public void Setup() { _object = new SortingAlgorithms(); }
public static void Main(string[] args) { sa = new SortingAlgorithms(); n_5 = new int[1000000]; n_6 = new int[10000000]; rnd = new Random(8); //Seed carefully chosen by the team for (int i = 0; i < n_6.Length; i++) { int nextRand = rnd.Next(); n_6[i] = nextRand; if (i < n_5.Length) { n_5[i] = nextRand; } } Console.WriteLine("Merge sort 10^5: "); for (int i = 0; i < 100; i++) { DateTime start = DateTime.Now; sa.MergeSort(n_5); DateTime end = DateTime.Now; Console.WriteLine(i + ") " + (end - start)); } Console.WriteLine("Merge sort 10^6: "); for (int i = 0; i < 100; i++) { DateTime start = DateTime.Now; sa.MergeSort(n_6); DateTime end = DateTime.Now; Console.WriteLine(i + ") " + (end - start)); } Console.WriteLine("Quick sort 10^5: "); for (int i = 0; i < 100; i++) { int[] copy = new int[n_5.Length]; for (int j = 0; j < copy.Length; j++) { copy[j] = n_5[j]; } DateTime start = DateTime.Now; sa.QuickSort(copy); DateTime end = DateTime.Now; Console.WriteLine(i + ") " + (end - start)); } Console.WriteLine("Quick sort 10^6: "); for (int i = 0; i < 100; i++) { int[] copy = new int[n_6.Length]; for (int j = 0; j < copy.Length; j++) { copy[j] = n_6[j]; } DateTime start = DateTime.Now; sa.QuickSort(copy); DateTime end = DateTime.Now; Console.WriteLine(i + ") " + (end - start)); } }