public void AddFiveItemsAndVerify()
        {
            int linkedListStackLast = 0;
            int arrayStackLast      = 0;

            for (int i = 1; i <= 5; i++)
            {
                linkedListStack.Push(i);
                arrayStack.Push(i);
            }

            Assert.AreEqual(linkedListStack.Peek(), 5, "invalid top element");
            Assert.AreEqual(linkedListStack.Count, 5, "invalid count");

            Assert.AreEqual(arrayStack.Peek(), 5, "invalid top element");
            Assert.AreEqual(arrayStack.Count, 5, "invalid count");

            while (linkedListStack.Count > 0)
            {
                linkedListStackLast = linkedListStack.Pop();
                arrayStackLast      = arrayStack.Pop();
            }
            Assert.AreEqual(linkedListStackLast, 1, "invalid last element");
            Assert.AreEqual(arrayStackLast, 1, "invalid last element");
        }
        public void LinkedListStackTest()
        {
            var stack = new LinkedListStack <int>();

            stack.Push(1);
            stack.Push(2);

            Assert.IsTrue(stack.ItemCount == 2);
            Assert.IsTrue(stack.IsEmpty() == false);
            Assert.IsTrue(stack.Peek() == 2);
            Assert.IsTrue(stack.Pop() == 2);
            Assert.IsTrue(stack.ItemCount == 1);
            stack.Pop();
            Assert.IsTrue(stack.IsEmpty());

            for (int i = 0; i < 1000; i++)
            {
                stack.Push(i);
            }

            Assert.IsTrue(stack.ItemCount == 1000);

            for (int i = 0; i < 1000; i++)
            {
                stack.Pop();
            }

            Assert.IsTrue(stack.ItemCount == 0);
        }
Exemple #3
0
        public void LinkedListStackPushTest()
        {
            for (var i = 0; i < Elements - 1; i++)
            {
                _linkedListStackStack.Pop();
            }

            Assert.AreEqual(0, _linkedListStackStack.Peek());
        }
        public void Peek_PushTwoItemsAndPop_ReturnsHeadElement()
        {
            var stack = new LinkedListStack <int>();

            stack.Push(1);
            stack.Push(2);
            stack.Pop();
            Assert.AreEqual(1, stack.Peek());
        }
Exemple #5
0
        public void LinkedListStackPushTest()
        {
            var linkedListStackStack = new LinkedListStack <int>();

            for (var i = 0; i < Elements; i++)
            {
                linkedListStackStack.Push(i * 10);
            }
            Assert.AreEqual(1000000000, linkedListStackStack.Peek());
        }
Exemple #6
0
        private string ShuntingYard(string input)
        {
            LinkedListStack <char> operators = new LinkedListStack <char>();
            Queue <char>           output    = new LinkedListQueue <char>();

            foreach (var i in input)
            {
                if (Char.IsNumber(i))
                {
                    output.Enqueue(i);
                }
                if (IsOperator(i))
                {
                    while (!operators.IsEmpty() && OperatorPrecedence(operators.Peek()) >= OperatorPrecedence(i))
                    {
                        output.Enqueue(operators.Pop());
                    }
                    operators.Push(i);
                }
                if (i == '(')
                {
                    operators.Push(i);
                }
                if (i == ')')
                {
                    while (operators.Peek() != '(')
                    {
                        output.Enqueue(operators.Pop());
                    }
                    operators.Pop();
                }
            }
            while (!operators.IsEmpty())
            {
                output.Enqueue(operators.Pop());
            }

            return(new string(output.ToArray()));
        }
Exemple #7
0
        static void Main(string[] args)
        {
            LinkedList      list  = new LinkedList();
            LinkedListStack stack = new LinkedListStack();
            LinkedListQueue queue = new LinkedListQueue();

            list.Add(56);
            list.Add(70);
            list.Add(90);
            list.Add(12);
            list.Add(30);
            list.Add(60);
            list.AddInReverseOrder(22);
            list.AddInReverseOrder(44);
            list.InsertAtParticularPosition(2, 12);
            list.Display();
            list.Total();
            list.DeleteFirst();
            list.DeleteLast();
            list.SearchValueInList(90);
            stack.Push(10);
            stack.Push(20);
            stack.Push(30);
            stack.Push(40);
            stack.Push(50);
            stack.Display();
            stack.Peek();
            stack.Pop();
            stack.IsEmpty();
            queue.Enqueue(12);
            queue.Enqueue(24);
            queue.Enqueue(36);
            queue.Enqueue(48);
            queue.Dequeue();
            queue.Display();
            Console.ReadKey();
        }
Exemple #8
0
 public void Push_pushToEmpty_expectTrue()
 {
     _teStack.Push("wo");
     Assert.AreEqual(_teStack.Peek(), "wo");
     Assert.AreEqual(_teStack.Count(), 1);
 }