Exemplo n.º 1
0
        public static void Show()
        {
            var numbers = Array.ConvertAll(FileUtilities.Read("cisla.txt"), int.Parse);
            var tree    = new Tree();

            foreach (var number in numbers)
            {
                tree.Insert(number);
            }

            var operations = new Dictionary <int, IOperation>
            {
                { 1, new FindOperation(tree) },
                { 2, new InsertOperation(tree) },
                { 3, new RemoveOperation(tree) }
            };

            while (true)
            {
                ConsoleUtilities.DisplayMenu(options: new[] { "1. Najit prvek", "2. Pridat prvek", "3. Odebrat prvek" });

                ConsoleUtilities.Prompt("\nZvolte moznost: ");
                var operation = ConsoleUtilities.GetUserInput();

                if (!operations.ContainsKey(operation))
                {
                    ConsoleUtilities.Prompt("\nNespravna volba. Ukonceni aplikace...\n");
                    break;
                }

                operations.Where(o => o.Key == operation).First().Value.Perform();

                ConsoleUtilities.Prompt($"\n{new string('-', 30)}\n");
            }
        }
Exemplo n.º 2
0
        public static void Show()
        {
            ConsoleUtilities.Prompt("Zadejte velikost zasobniku: ");
            var stack = new Stack(size: ConsoleUtilities.GetUserInput());

            var operations = new Dictionary <int, IOperation>
            {
                { 1, new PushOperation(stack) },
                { 2, new PopOperation(stack) }
            };

            while (true)
            {
                ConsoleUtilities.DisplayMenu(options: new[] { "\n1. Pridat", "2. Odebrat", "3. Odejit" });

                ConsoleUtilities.Prompt("\nZvolte moznost: ");
                var operation = ConsoleUtilities.GetUserInput();

                if (!operations.ContainsKey(operation))
                {
                    ConsoleUtilities.Prompt("\nUkonceni aplikace...\n");
                    break;
                }

                operations.Where(o => o.Key == operation).First().Value.Perform();

                ConsoleUtilities.Prompt($"\n{new string('-', 30)}\n");
            }
        }
Exemplo n.º 3
0
        public static void Show()
        {
            var numbers = Array.ConvertAll(FileUtilities.Read("counting.txt"), int.Parse);

            var search = new Search(numbers);

            while (true)
            {
                ConsoleUtilities.Prompt("Zadejte hledany prvek: ");
                var number = ConsoleUtilities.GetUserInput();

                var count = search.Lookup(number);

                ConsoleUtilities.Prompt($"\n{(count > 0 ? $"{number} bylo nalezeno {count} krat.\n" : $"{number} nebylo nalezeno.\n")}\n");
            }
Exemplo n.º 4
0
        public static void Show()
        {
            ConsoleUtilities.Prompt("Zadejte minimum: ");
            var min = ConsoleUtilities.GetUserInput();

            ConsoleUtilities.Prompt("Zadejte maximum: ");
            var max = ConsoleUtilities.GetUserInput();

            ConsoleUtilities.Prompt("Kolik cisel je treba vygenerovat? ");
            var count = ConsoleUtilities.GetUserInput();

            FileUtilities.DeleteIfExists(path);

            var builder = new StringBuilder();

            for (var index = 0; index < count; index++)
            {
                builder.AppendLine(Generator.Generate(min, max).ToString());
            }

            FileUtilities.Write(path, builder.ToString().Trim());

            ConsoleUtilities.Prompt("\nHotovo!\n");
        }