Exemple #1
0
        static void Main(string[] args)
        {
            var queue = new FrontMiddleBackQueue();

            queue.PushFront(1);
            queue.PushBack(2);
            queue.PushMiddle(3);
            queue.PushMiddle(4);
            Console.WriteLine(queue.PopFront());
            Console.WriteLine(queue.PopMiddle());
            Console.WriteLine(queue.PopMiddle());
            Console.WriteLine(queue.PopBack());
            Console.WriteLine(queue.PopFront());
        }
        public void Test_GenericStr(string[] commands, string argsStr, int?[] expected)
        {
            var argsMatrix = ArrayHelper.MatrixFromString <int>(argsStr);

            System.Console.WriteLine(argsMatrix.Length);

            var sol = new FrontMiddleBackQueue();

            int?[] res = new int?[argsMatrix.Length];
            for (int i = 0; i < commands.Length; i++)
            {
                int?arg = null;
                if (argsMatrix[i].Length > 0)
                {
                    arg = argsMatrix[i][0];
                }

                res[i] = ExecuteOperation(commands[i], sol, arg);
            }

            CollectionAssert.AreEquivalent(res, expected);
        }
        private int?ExecuteOperation(string operation, FrontMiddleBackQueue queue, int?arg)
        {
            int?res = null;

            switch (operation)
            {
            case "FrontMiddleBackQueue":
                break;

            case "pushFront":
                queue.PushFront((int)arg);
                break;

            case "pushBack":
                queue.PushBack((int)arg);
                break;

            case "pushMiddle":
                queue.PushMiddle((int)arg);
                break;

            case "popFront":
                res = queue.PopFront();
                break;

            case "popMiddle":
                res = queue.PopMiddle();
                break;

            case "popBack":
                res = queue.PopBack();
                break;
            }

            return(res);
        }