static void Main() { ArraySorting searcher = new ArraySorting(); List <int> list = searcher.Input(); searcher.Max(list); }
public void TestMethod_ForArraySorting() { int[] arr1 = { 1, 3, 4, 6, 8 }; int[] arr2 = { 2, 5, 7, 9, 10 }; int[] arr3 = { }; int[] arr4 = { -5, -2, -4, -3, -1, 0 }; ArraySorting arraySorting = new ArraySorting(); Assert.IsTrue(IsEqual(arraySorting.SortAndMergeArray(arr1, arr2), new Int32[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })); Assert.IsTrue(IsEqual(arraySorting.SortAndMergeArray(arr1, arr3), new Int32[] { 1, 3, 4, 6, 8 })); Assert.IsTrue(IsEqual(arraySorting.SortAndMergeArray(arr1, arr4), new Int32[] { -5, -4, -3, -2, -1, 0, 1, 3, 4, 6, 8 })); }
public static void Main(string[] args) { int[] array1 = new int[100]; int[] array2 = new int[100]; Random random = new Random(); for (int i = 0; i < array1.Length; i++) { array1[i] = random.Next(1, 1000); } for (int i = 0; i < array1.Length; i++) { array2[i] = random.Next(1, 1000); } Console.WriteLine("Array1 before sorting:\n"); foreach (int a in array1) { Console.Write(a + " "); } Console.WriteLine("\n"); Console.WriteLine("Array1 after merge sorting:\n"); ArraySorting.MergeSort(array1); foreach (int a in array1) { Console.Write(a + " "); } Console.WriteLine("\n"); Console.WriteLine("Array2 before sorting:\n"); foreach (int a in array2) { Console.Write(a + " "); } Console.WriteLine("\n"); Console.WriteLine("Array2 after quick sorting:\n"); ArraySorting.QuickSort(array2); foreach (int a in array2) { Console.Write(a + " "); } Console.ReadKey(); }
private static void RunArraySorting() { PrintHeader("Sorting Array"); int[] mas = new int[] { 10, 5, 3, 4, 9 }; Console.WriteLine("Original mas:"); PrintIntMatrix(mas); var masTask = new ArraySorting(); int [] ascSortedArray = masTask.SortArray(mas, SortingOrder.Asc); Console.WriteLine($"Sorted by Asc"); PrintIntMatrix(ascSortedArray); int[] descSortedArray = masTask.SortArray(mas, SortingOrder.Desc); Console.WriteLine($"Sorted by Desc"); PrintIntMatrix(descSortedArray); PrintWait(); }
public void MergeSort_Test() { int[] array1 = new int[100]; int[] array2 = new int[100]; Random random = new Random(); for (int i = 0; i < array1.Length; i++) { array1[i] = random.Next(1, 1000); } array1.CopyTo(array2, 0); ArraySorting.MergeSort(array1); array2 = array2.OrderBy(x => x).ToArray(); Assert.AreEqual(array2, array1); }
private static void RunArraySortingVerification() { PrintHeader("Sorting Array Verification"); int[] mas = new int[] { 10, 5, 3, 4, 9 }; Console.WriteLine("Original mas:"); PrintIntMatrix(mas); var masTask = new ArraySorting(); int[] ascSortedArray = masTask.SortArray(mas, SortingOrder.Asc); int[] descSortedArray = masTask.SortArray(mas, SortingOrder.Desc); bool VerifySortedArrayAsc = masTask.ValidateArraySorting(ascSortedArray, SortingOrder.Asc); Console.WriteLine($"Sorted by Asc:{VerifySortedArrayAsc}"); bool VerifySortedArrayDesc = masTask.ValidateArraySorting(descSortedArray, SortingOrder.Desc); Console.WriteLine($"Sorted by Desc:{VerifySortedArrayDesc}"); PrintWait(); }
private static void Main(string[] args) { var array = new [] { "A", "9", "d", "Ab", "ä", "a", "aB", "m", "aa", "ab", "ss", "ß", "Ä", "0", "Äb", "äb", "Z", "z" }; Console.OutputEncoding = System.Text.Encoding.Unicode; Console.WriteLine("Initial"); Console.WriteLine(string.Join(", ", array)); ArraySorting.Sort(array); Console.WriteLine("Ascending"); Console.WriteLine(string.Join(", ", array)); ArraySorting.Sort(array, false); Console.WriteLine("Descending"); Console.WriteLine(string.Join(", ", array)); Console.ReadKey(); }
public static void Main() { Console.WriteLine("Hello"); int[] arr1 = { 1, 3, 4, 6, 8 }; int[] arr2 = { 2, 5, 7, 9, 10 }; int[] arr3 = {}; int[] arr4 = { -5, -2, -4, -3, -1, 0 }; Game game = new Game(); ArraySorting arraySorting = new ArraySorting(); Console.WriteLine(game.MacroPolo(20)); var sortedArray = arraySorting.SortAndMergeArray(arr1, arr4); for (int i = 0; i < sortedArray.Length; i++) { Console.Write(sortedArray[i]); } Console.ReadKey(); }
static void Main(string[] args) { // make a string string input = "Hello C sharp world"; /// <heading>Remove space character</heading> // make an object to implement the function StringManipulate rmSpaceChar = new StringManipulate(); // make an empty string to receive a string without spaces string my_str = ""; // remove the space then assign it my_str = rmSpaceChar.rmSpaceChar(input); /// <heading>Convert the all uppercase letter in the string into lowercase</heading> my_str = my_str.ToLower(); /// <heading>Sort the string</heading> ArraySorting arrSort = new ArraySorting(); // sort the array my_str = arrSort.SortArray(my_str); /// <heading>Calculate the frequency of character in the string</heading> // create an instance to implement the method to count the frequency Frequency freq = new Frequency(); // make a dictionary Dictionary <char, int> my_dict = new Dictionary <char, int>(); // initialize to the dictionary my_dict = freq.Frequency_of_char(my_str); // print out the dictionary, each key-value // make a KeyValuePair instance to access to the pair of values in Dictionary foreach (KeyValuePair <char, int> word in my_dict) { // Access the `Key` and `Value` field of the `word` instance Console.WriteLine("\'{0}\' : {1}", word.Key, word.Value); } }
public void Sort_Array_ArraySortedByRowsDescendingMax(int[][] array, int[][] sortedArray) { ArraySorting.Sort(array, new MaxInRowsDescendingComparer()); Array.Reverse(sortedArray); CheckArraysForEquality(array, sortedArray); }
public void Sort_Array_ArraySortedByRowsAscendingSum(int[][] array, int[][] sortedArray) { ArraySorting.Sort(array, new SumInRowsAscendingComparer()); CheckArraysForEquality(array, sortedArray); }
public void Sort_ArrayWithNullRows_ThrowsArgumentNullException(int[][] array, int[][] result) { Assert.Throws <ArgumentNullException>(() => ArraySorting.Sort(array, new MaxInRowsAscendingComparer())); }
public void Sort_NullArray_ThrowsArgumentNullException(int[][] array) { Assert.Throws <ArgumentNullException>(() => ArraySorting.Sort(array, new SumInRowsAscendingComparer())); }
public void MergeSort_ArrayLength0_ThrowsArgumentException() { int[] array = new int[0]; Assert.Throws <ArgumentException>(() => ArraySorting.MergeSort(array)); }
public void MergeSort_NullArray_ThrowsNullReferenceException() { int[] array = null; Assert.Throws <NullReferenceException>(() => ArraySorting.MergeSort(array)); }