static void Main(string[] args)
        {
            var stack = new CustomStack <string>(2);

            stack.Push("Pesho");
            stack.Push("Gosho");
            stack.Push("Penio");

            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("Capacity {0}", stack.Capacity);
            Console.WriteLine("Count {0}", stack.Count);

            stack.Pop();
            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("Capacity {0}", stack.Capacity);
            Console.WriteLine("Count {0}", stack.Count);
        }
Example #2
0
        public static void TestStack()
        {
            CustomStack <string> customStack = new CustomStack <string>();

            customStack.Push(new string[] { "10" });
            customStack.Push(new string[] { "20" });
            customStack.Push(new string[] { "30" });

            Console.WriteLine(customStack.Pop());
            Console.WriteLine(customStack.Pop());
            Console.WriteLine(customStack.Pop());
            Console.WriteLine(customStack.Pop());
        }
Example #3
0
        public static void Task()
        {
            string input = Console.ReadLine();
            CustomStack <string> customStack = new CustomStack <string>();

            while (input != "END")
            {
                if (input.Contains("Push"))
                {
                    IEnumerable <string> elements = input
                                                    .Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                                    .Skip(1);

                    customStack.Push(elements);
                }
                else if (input == "Pop")
                {
                    customStack.Pop();
                }

                input = Console.ReadLine();
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (string item in customStack)
                {
                    if (item != null)
                    {
                        Console.WriteLine(item);
                    }
                }
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            var endCommand  = "END";
            var command     = Console.ReadLine();
            var customStack = new CustomStack <string>();

            while (command != endCommand)
            {
                var commandArgs = command.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                                  .ToArray();
                try
                {
                    switch (commandArgs[0])
                    {
                    case "Pop":
                        customStack.Pop();
                        break;

                    case "Push":
                        var elements = commandArgs.Skip(1).ToArray();
                        customStack.Push(elements);
                        break;
                    }
                }
                catch (InvalidOperationException message)
                {
                    Console.WriteLine(message.Message);
                }

                command = Console.ReadLine();
            }

            PrintsAllElements(customStack);
            PrintsAllElements(customStack);
        }
Example #5
0
        static void Main(string[] args)
        {
            var command = Console.ReadLine()
                          .Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            var stack = new CustomStack <string>();


            while (command[0] != "END")
            {
                if (command[0] == "Push")
                {
                    stack.Push(command.Skip(1).ToList());
                }
                else if (command[0] == "Pop")
                {
                    stack.Pop();
                }

                command = Console.ReadLine()
                          .Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }
            for (int i = 0; i < 2; i++)
            {
                foreach (var item in stack)
                {
                    Console.WriteLine(item);
                }
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            CustomStack <int> myStack = new CustomStack <int>();

            string command = string.Empty;

            while ((command = Console.ReadLine()) != "END")
            {
                if (command.Contains("Push"))
                {
                    command = command.Remove(0, 5);
                    List <int> currList = command.Split(", ").Select(int.Parse).ToList();
                    for (int i = 0; i < currList.Count; i++)
                    {
                        myStack.Push(currList[i]);
                    }
                }
                else if (command.Contains("Pop"))
                {
                    myStack.Pop();
                }
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (var item in myStack)
                {
                    Console.WriteLine(item);
                }
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            //Console.WriteLine(ReverseString("abcd"));
            //Console.WriteLine(BalancedExpression("ab{<>}cd"));

            var customStack = new CustomStack(5);

            Console.WriteLine($"IsEmpty?: {customStack.IsEmpty()}");

            customStack.Push(5);
            customStack.Push(10);
            customStack.Push(15);
            Console.WriteLine("Before Pop: ");
            customStack.Print();

            Console.WriteLine($"Pop triggered: {customStack.Pop()}");

            Console.WriteLine("After Pop: ");
            customStack.Print();

            Console.WriteLine($"Peek triggered: {customStack.Peek()}");
            Console.WriteLine($"IsEmpty?: {customStack.IsEmpty()}");
        }
Example #8
0
        public static void Main(string[] args)
        {
            var myStack = new CustomStack <int>();

            string input = "";

            while ((input = Console.ReadLine()) != "END")
            {
                var splittedInput = input
                                    .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                                    .ToList();

                var command = splittedInput[0];

                switch (command)
                {
                case "Push":
                    var elements = splittedInput
                                   .Skip(1)
                                   .ToList();

                    foreach (var item in elements)
                    {
                        myStack.Push(int.Parse(item));
                    }
                    break;

                case "Pop":
                    if (myStack.Count == 0)
                    {
                        Console.WriteLine("No elements");
                    }
                    else
                    {
                        myStack.Pop();
                    }
                    break;
                }
            }

            foreach (var item in myStack)
            {
                Console.WriteLine(item);
            }

            foreach (var item in myStack)
            {
                Console.WriteLine(item);
            }
        }
Example #9
0
        static void Main(string[] args)
        {
            var input = string.Empty;

            CustomStack <string> stack = new CustomStack <string>();

            while ((input = Console.ReadLine()) != "END")
            {
                var commandArgs = input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                var command     = commandArgs[0];

                switch (command)
                {
                case "Push":
                    var items = commandArgs.Skip(1).ToArray();
                    foreach (var item in items)
                    {
                        stack.Push(item);
                    }
                    break;

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

            try
            {
                for (int i = 0; i < 2; i++)
                {
                    foreach (var item in stack)
                    {
                        Console.WriteLine(item);
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #10
0
        static void Main()
        {
            string commandLine = String.Empty;

            CustomStack <string> customStack = new CustomStack <string>();

            while ((commandLine = Console.ReadLine()) != "END")
            {
                string[] commands = commandLine
                                    .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (commands[0] == "Push")
                {
                    string[] elements = commands
                                        .Skip(1)
                                        .ToArray();

                    for (int i = 0; i < elements.Length; i++)
                    {
                        customStack.Push(elements[i]);
                    }
                }

                else if (commands[0] == "Pop")
                {
                    if (customStack.Count() == 0)
                    {
                        Console.WriteLine("No elements");
                    }

                    else
                    {
                        customStack.Pop();
                    }
                }
            }

            foreach (var item in customStack)
            {
                Console.WriteLine(item);
            }

            foreach (var item in customStack)
            {
                Console.WriteLine(item);
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            var    myStack = new CustomStack <int>();
            string input   = Console.ReadLine();

            while (input != "END")
            {
                string[] tokens  = input.Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries);
                string   command = tokens[0];

                switch (command)
                {
                case "Push":
                    var ints = tokens.Skip(1).Select(int.Parse).ToArray();
                    myStack.Push(ints);
                    break;

                case "Pop":
                    try
                    {
                        myStack.Pop();
                    }
                    catch
                    {
                        Console.WriteLine("No elements");
                    }
                    break;

                default:
                    break;
                }

                input = Console.ReadLine();
            }

            foreach (var item in myStack)
            {
                Console.WriteLine(item);
            }
            foreach (var item in myStack)
            {
                Console.WriteLine(item);
            }
        }
Example #12
0
        public static void Main()
        {
            string commands = Console.ReadLine();

            CustomStack <int> stack = new CustomStack <int>();

            while (commands != "END")
            {
                string[] splitedCommands = commands.Split(" ", 2);//splits input into two elements by the first space

                string command = splitedCommands[0];

                if (command == "Push")
                {
                    int[] elements = splitedCommands[1]
                                     .Split(", ")
                                     .Select(int.Parse)
                                     .ToArray();

                    stack.Push(elements);
                }
                else if (command == "Pop")
                {
                    try
                    {
                        stack.Pop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                commands = Console.ReadLine();
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (var element in stack)
                {
                    Console.WriteLine(element);
                }
            }
        }
Example #13
0
        static void Main()
        {
            CustomStack <int> stack = new CustomStack <int>();

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

                string[] splittedInput = input.Split(" ", 2);

                string command = splittedInput[0];

                if (command == "Push")
                {
                    int[] numbers = splittedInput[1].Split(", ").Select(int.Parse).ToArray();
                    stack.Push(numbers);
                }
                else
                {
                    try
                    {
                        stack.Pop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (var number in stack)
                {
                    Console.WriteLine(number);
                }
            }
        }
Example #14
0
        static void Main()
        {
            var custumStack = new CustomStack <int>();

            while (true)
            {
                List <string> input = Console.ReadLine()
                                      .Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries)
                                      .ToList();

                string command = input[0];

                if (command == "END")
                {
                    break;
                }
                else if (command == "Push")
                {
                    input.RemoveAt(0);

                    int[] numbers = input
                                    .Select(int.Parse)
                                    .ToArray();

                    custumStack.Push(numbers);
                }
                else if (command == "Pop")
                {
                    custumStack.Pop();
                }
            }

            foreach (var item in custumStack)
            {
                Console.WriteLine($"{item}");
            }

            foreach (var item in custumStack)
            {
                Console.WriteLine($"{item}");
            }
        }
Example #15
0
        public static void Main()
        {
            CustomStack <int> myStack = new CustomStack <int>();
            string            input   = Console.ReadLine();

            while (!input.Equals("END"))
            {
                string[] args    = input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                string   command = args[0];

                switch (command)
                {
                case "Push":

                    myStack.Push(args.Skip(1).Select(int.Parse));
                    break;

                case "Pop":

                    try
                    {
                        myStack.Pop();
                    }
                    catch (InvalidOperationException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    break;
                }

                input = Console.ReadLine();
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (int element in myStack)
                {
                    Console.WriteLine(element);
                }
            }
        }
        public static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            string command = Console.ReadLine();

            while (command != "END")
            {
                string action = command.Split()[0];

                switch (action)
                {
                case "Push":
                    int[] nums = command
                                 .Split(new string[] { " ", "," }, StringSplitOptions.RemoveEmptyEntries)
                                 .Skip(1).Select(int.Parse)
                                 .ToArray();
                    stack.Push(nums);
                    break;

                case "Pop":
                    try
                    {
                        stack.Pop();
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    break;
                }
                command = Console.ReadLine();
            }
            for (int i = 0; i < 2; i++)
            {
                // Console.WriteLine(string.Join("\n", stack)); or this way instead of foreach
                foreach (var element in stack)
                {
                    Console.WriteLine(element);
                }
            }
        }
Example #17
0
        static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] command = input.Split(" ", 2);

                switch (command[0])
                {
                case "Push":

                    int[] integers = command[1].Split(", ").Select(int.Parse).ToArray();
                    stack.Push(integers);

                    break;

                case "Pop":

                    if (stack.Count == 0)
                    {
                        Console.WriteLine("No elements");
                    }
                    else
                    {
                        stack.Pop();
                    }
                    break;
                }
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (var item in stack)
                {
                    Console.WriteLine(item);
                }
            }
        }
Example #18
0
        static void Main(string[] args)
        {
            string[]             input = Console.ReadLine().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray();
            CustomStack <string> stack = new CustomStack <string>(input);


            while (true)
            {
                try
                {
                    string command = Console.ReadLine();
                    if (command == "Pop")
                    {
                        stack.Pop();
                    }
                    string[] inputargs = command.Split();

                    if (inputargs[0] == "Push")
                    {
                        stack.Push(inputargs[1]);
                    }
                    if (command == "END")
                    {
                        IEnumerable <string> final = stack.Reverse();
                        foreach (var item in final)
                        {
                            Console.WriteLine(item);
                        }
                        foreach (var item in final)
                        {
                            Console.WriteLine(item);
                        }
                        break;
                    }
                }
                catch (InvalidOperationException io)
                {
                    Console.WriteLine(io.Message);
                }
            }
        }
Example #19
0
        static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            string input;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] cmdArgs = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   command = cmdArgs[0];
                if (command == "Push")
                {
                    string[] itemsToPush = cmdArgs.Skip(1).ToArray();
                    foreach (var num in itemsToPush)
                    {
                        stack.Push(int.Parse(num.TrimEnd(',')));
                    }
                }
                else if (command == "Pop")
                {
                    try
                    {
                        stack.Pop();
                    }
                    catch (InvalidOperationException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }

            foreach (var num in stack)
            {
                Console.WriteLine(num);
            }

            foreach (var num in stack)
            {
                Console.WriteLine(num);
            }
        }
        static void Main(string[] args)
        {
            int[] numbers = Console.ReadLine()
                            .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                            .Skip(1)
                            .Select(int.Parse)
                            .ToArray();

            CustomStack <int> stack = new CustomStack <int>(numbers);

            string input = "";

            while ((input = Console.ReadLine()) != "END")
            {
                if (input == "Pop")
                {
                    try
                    {
                        stack.Pop();
                    }
                    catch (InvalidOperationException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    string[] data  = input.Split();
                    int      value = int.Parse(data[1]);
                    stack.Push(value);
                }
            }

            if (stack.Count > 0)
            {
                Console.WriteLine(stack);
                Console.WriteLine(stack);
            }
        }
Example #21
0
        static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            string line = Console.ReadLine();

            while (line != "END")
            {
                string[] command = line.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();

                if (command[0] == "Push")
                {
                    stack.Push(command.Skip(1).Select(x => x.Replace(",", "")).Select(int.Parse).ToArray());
                }
                else if (command[0] == "Pop")
                {
                    try
                    {
                        stack.Pop();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("No elements");
                    }
                }

                line = Console.ReadLine();
            }

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

            foreach (var element in stack)
            {
                Console.WriteLine(element);
            }
        }
Example #22
0
        static void Main(string[] args)
        {
            var customStack = new CustomStack <int>();
            var input       = Console.ReadLine();

            while (input != "END")
            {
                var arr = input.Split(" ", 2);

                var stringCommand = arr[0];

                if (stringCommand == "Push")
                {
                    var numbers = arr[1].Split(", ").Select(int.Parse).ToArray();
                    customStack.Push(numbers);
                }
                else
                {
                    try
                    {
                        customStack.Pop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                input = Console.ReadLine();
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (var g in customStack)
                {
                    Console.WriteLine(g);
                }
            }
        }
        public static void Main(string[] args)
        {
            string            line        = Console.ReadLine();
            CustomStack <int> customStack = new CustomStack <int>();

            while (line != "END")
            {
                string[] input = line
                                 .Split(new string[] { ", ", " " }, StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();

                string command = input[0];
                try
                {
                    switch (command)
                    {
                    case "Push":
                        customStack.Push(input.Skip(1).Select(int.Parse).ToList());
                        break;

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

                line = Console.ReadLine();
            }

            for (int i = 0; i < 2; i++)
            {
                Console.WriteLine(string.Join(Environment.NewLine, customStack));
            }
        }
Example #24
0
        public static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] tokens = input
                                  .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

                string command = tokens[0];

                if (command == "Push")
                {
                    for (int currentNumber = 1; currentNumber < tokens.Length; currentNumber++)
                    {
                        stack.Push(int.Parse(tokens[currentNumber]));
                    }
                }
                else if (command == "Pop")
                {
                    stack.Pop();
                }
            }

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

            foreach (var number in stack)
            {
                Console.WriteLine(number);
            }
        }
Example #25
0
        public static void Main()
        {
            string[]             input      = Console.ReadLine().Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            CustomStack <string> collection = new CustomStack <string>();

            while (input[0] != "END")
            {
                if (input[0] == "Push")
                {
                    collection.Push(input.Skip(1).ToArray());
                }
                else if (input[0] == "Pop")
                {
                    try
                    {
                        collection.Pop();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                input = Console.ReadLine().Split();
            }

            foreach (var item in collection)
            {
                Console.WriteLine(item);
            }

            foreach (var item in collection)
            {
                Console.WriteLine(item);
            }
        }
Example #26
0
        static void Main(string[] args)
        {
            CustomStack mystack = new CustomStack();
            string      command = string.Empty;

            while ((command = Console.ReadLine()) != "END")
            {
                if (command == "Pop")
                {
                    try
                    {
                        mystack.Pop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("No elements");
                    }
                }
                else
                {
                    int[] commandArr = command.Split(new string[] { ", ", " " }, StringSplitOptions.RemoveEmptyEntries)
                                       .Skip(1).Select(int.Parse).ToArray();
                    mystack.Push(commandArr);
                }
            }

            foreach (var item in mystack)
            {
                Console.WriteLine(item);
            }

            foreach (var item in mystack)
            {
                Console.WriteLine(item);
            }
        }
Example #27
0
        static void Main(string[] args)
        {
            var customStack = new CustomStack <string>();

            while (true)
            {
                var input = Console.ReadLine().Split(new [] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                switch (input[0])
                {
                case "Push":
                    customStack.Push(input.Skip(1).ToArray());
                    break;

                case "Pop":
                    try
                    {
                        customStack.Pop();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    break;

                case "END":
                    for (int i = 0; i < 2; i++)
                    {
                        foreach (var item in customStack)
                        {
                            Console.WriteLine(item);
                        }
                    }
                    return;
                }
            }
        }
Example #28
0
        static void Main(string[] args)
        {
            CustomStack <int> customStack = new CustomStack <int>();

            string input = Console.ReadLine();

            while (input != "END")
            {
                if (input == "Pop")
                {
                    try
                    {
                        customStack.Pop();
                    }
                    catch (IndexOutOfRangeException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    customStack.Push(input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                                     .Skip(1)
                                     .Select(int.Parse)
                                     .ToArray());
                }
                input = Console.ReadLine();
            }
            for (int i = 0; i < 2; i++)
            {
                foreach (var item in customStack)
                {
                    Console.WriteLine(item);
                }
            }
        }