Example #1
0
        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();
        }
Example #2
0
        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();
        }
Example #3
0
        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);
            }
        }