Example #1
0
        static void Main()
        {
            int choise;

            do
            {
                Console.WriteLine(@"
==============================
| Available Representations: |
| 1. Selection Sort          |
| 2. Insertion Sort          |
| 3. Merdge Sort             |
| 4. Bubble Sort             |
| 5. Quick Sort              |
| 6. Cocktail Sort           |
|----------------------------|
| 7. Clear Console           |
| 8. Exit                    |
==============================
");
                choise = ConsoleExtensions.GetIntNumber(8, 1);

                switch (choise)
                {
                case 1:
                    SortConsoleRepresentator.Represent(new SelectionSort());
                    break;

                case 2:
                    SortConsoleRepresentator.Represent(new InsertionSort());
                    break;

                case 3:
                    SortConsoleRepresentator.Represent(new MerdgeSort());
                    break;

                case 4:
                    SortConsoleRepresentator.Represent(new BubbleSort());
                    break;

                case 5:
                    SortConsoleRepresentator.Represent(new QuickSort());
                    break;

                case 6:
                    SortConsoleRepresentator.Represent(new CocktailSort());
                    break;

                case 7:
                    Console.Clear();
                    break;

                default:
                    break;
                }
            } while (choise != 8);
        }
Example #2
0
        static void Main(string[] args)
        {
            int choise;

            Console.SetWindowSize(200, 50);

            do
            {
                Console.WriteLine(@"
=============================================================
| Variance is the abbility of interfaces and methods        |
| to work with ancestor instead of descendant or vice versa |
=============================================================
| Available Representations:                        |
| 1. Covariance (descendant instead of ancestor)    |
| 2. Contrvariance (ancestor instead of descendant) |
| 3. Invariance (strong types without anything)     |
|---------------------------------------------------|
| 4. Clear Console           |
| 5. Exit                    |
==============================
");
                choise = ConsoleExtensions.GetIntNumber(5, 1);

                switch (choise)
                {
                case 1:
                    VarianceConsoleRepresetnetion.Represent(new Covariance());
                    break;

                case 2:
                    VarianceConsoleRepresetnetion.Represent(new Contrvariance());
                    break;

                case 3:
                    VarianceConsoleRepresetnetion.Represent(new Invariance());
                    break;

                case 4:
                    Console.Clear();
                    break;

                default:
                    break;
                }
            } while (choise != 5);
        }
Example #3
0
        public static void Represent(ISort sorter)
        {
            string _sortRuleName = string.Empty;
            int    length        = ConsoleExtensions.GetIntNumber(30, 5);

            int[] source = RandomGenerator.GetRandomIntArray(100, 0, length);

            Console.WriteLine($@"
=========================================
| Alhorithm: {sorter.Title}
| Initial array: {source.Represent()}
=========================================
| Available Actions:                    |
| 1. Sort generated array by descending |
| 2. Sort generated array by ascending  |
=========================================
");
            switch (ConsoleExtensions.GetIntNumber(2, 1))
            {
            case 1:
                _sortRuleName = "DESCENDING";
                sorter.Descending(source);
                break;

            case 2:
                _sortRuleName = "ASCENDING";
                sorter.Ascending(source);
                break;

            default:
                break;
            }

            Console.WriteLine($@"
========================================
|  {_sortRuleName,10} sort with description    |
========================================
|     Result is: {source.Represent()}
========================================");
        }
Example #4
0
        private static void Main(string[] args)
        {
            Console.WriteLine("=== Call Stack In Recurent Algorithms ===");
            Console.WriteLine(@"
Available Actions:
============================================
| 1. Factorial call stack representation   |
| 2. Binary tree call stack representation |
============================================
");
            int choice = ConsoleExtensions.GetIntNumber(2, 1);

            if (choice == 1)
            {
                Console.WriteLine("=== Factorial Selected ===");
                int number = ConsoleExtensions.GetIntNumber(12, 5);

                var factorial = new FactorialWithDescription();
                int result    = factorial.RecurentFind(number);

                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(factorial.Description);
                Console.ResetColor();

                Console.WriteLine($@"
============================
| Factorial is: {result,10} |
============================
");
            }

            if (choice == 2)
            {
                Console.WriteLine("=== Binary Tree Selected ===");
                int length = ConsoleExtensions.GetIntNumber(30, 10);

                int[] source = RandomGenerator.GetRandomIntArray(16, 1, length);
                Console.WriteLine($@"
===========================================================
| Initial array: {source.Represent()}
===========================================================
");
                var tree = new Node();
                foreach (var item in source)
                {
                    tree.Data = item;
                }

                var treeWalker = new WalkerWithDescription();
                var result     = treeWalker.RecurentWalk(tree).ToList();

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(treeWalker.Description);
                Console.ResetColor();

                Console.WriteLine($@"
===========================================================
| Result list: {result.Represent()}
===========================================================
");
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }