Exemplo n.º 1
0
        static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "END")
                {
                    break;
                }
                var parts = input.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts[0] == "Push")
                {
                    var nums = parts.Skip(1).Select(int.Parse).ToArray();
                    foreach (var item in nums)
                    {
                        stack.Push(item);
                    }
                }
                else if (parts[0] == "Pop")
                {
                    stack.Pop();
                }
            }
            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            while (true)
            {
                string command = Console.ReadLine();
                if (command == "END")
                {
                    break;
                }

                string[] tokens = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                switch (tokens[0])
                {
                case "Push":
                    int[] elements = tokens.Skip(1)
                                     .Select(i => i.Split(',').First())
                                     .Select(int.Parse)
                                     .ToArray();
                    stack.Push(elements);
                    break;

                case "Pop":
                    try
                    {
                        stack.Pop();
                    }
                    catch (InvalidOperationException ioe)
                    {
                        Console.WriteLine(ioe.Message);
                    }
                    break;
                }
            }

            foreach (int number in stack)
            {
                Console.WriteLine(number);
            }

            foreach (int number in stack)
            {
                Console.WriteLine(number);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var myStack = new CustomStack <string>();

            while (true)
            {
                var input = Console.ReadLine().Split(new char[] { ',', ' ' }
                                                     , StringSplitOptions.RemoveEmptyEntries);

                if (input[0] == "END")
                {
                    break;
                }

                if (input[0] == "Push")
                {
                    var elements = input.Skip(1).ToArray();
                    myStack.Push(elements);
                }
                else if (input[0] == "Pop")
                {
                    try
                    {
                        myStack.Pop();
                    }
                    catch (InvalidOperationException ioe)
                    {
                        Console.WriteLine(ioe.Message);
                    }
                }
            }

            if (myStack.MyCustomStack.Count > 0)
            {
                for (int i = 0; i < 2; i++)
                {
                    foreach (var element in myStack)
                    {
                        Console.WriteLine(element);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void Main()
        {
            CustomStack <string> test = new CustomStack <string>();

            while (true)
            {
                string command = Console.ReadLine();

                if (command.Equals("END"))
                {
                    break;
                }

                string[] data   = command.Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(x => x.TrimEnd(',')).ToArray();
                string   action = data[0];

                try
                {
                    switch (action)
                    {
                    case "Push":

                        List <string> elementsToPush = data.Skip(1).ToList();
                        test.Push(elementsToPush);
                        break;

                    case "Pop":
                        test.Pop();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (var item in test)
            {
                Console.WriteLine(item);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            CustomStack <string> collections = new CustomStack <string>();

            while (input != "END")
            {
                string[] token = input.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                switch (token[0])
                {
                case "Push":
                {
                    collections.Push(token);
                }
                break;

                case "Pop":
                {
                    collections.Pop();
                }
                break;
                }

                input = Console.ReadLine();
            }

            collections.Collections.Reverse();
            foreach (var element in collections.Collections)
            {
                Console.WriteLine(element);
            }

            foreach (var element in collections.Collections)
            {
                Console.WriteLine(element);
            }
        }