static void Stack()
        {
            CustomStack cs = new CustomStack();

            cs.Push(10);

            var tmp = cs.GetItem();

            for (int i = 0; i < tmp.Length; i++)
            {
                Console.WriteLine("Item -> " + tmp[i]);
            }

            cs.Pop();
            cs.Pop();
            Console.WriteLine("After Pop :");
            tmp = cs.GetItem();
            for (int i = 0; i < tmp.Length; i++)
            {
                Console.WriteLine("Item -> " + tmp[i]);
            }

            cs.Push(40);
            Console.WriteLine("After push 40 : ");
            tmp = cs.GetItem();
            for (int i = 0; i < tmp.Length; i++)
            {
                Console.WriteLine("Item -> " + tmp[i]);
            }
        }
    private void Start()
    {
        CustomStack <int> a = new CustomStack <int>(1);

        a.Push(1);
        a.Push(2);
        a.Push(3);
        a.Push(4);
        Assert.AreEqual(a.Peek(), 4);

        foreach (int i in a)
        {
            Debug.Log("i: " + i);
        }

        Assert.AreEqual(a.Pop(), 4);
        Assert.AreEqual(a.Pop(), 3);
        Assert.AreEqual(a.Pop(), 2);
        Assert.AreEqual(a.Pop(), 1);
        try {
            a.Pop();
        } catch {
            Debug.Log("Popping empty stack returned error as expected");
        }
    }
        private static void Main()
        {
            var studentStack = new CustomStack<Student>();
            studentStack.Push(new Student("Pesho", 22));
            studentStack.Push(new Student("Penka", 41));
            studentStack.Push(new Student("Gosho", 7));
            studentStack.Push(new Student("Kuci", 15));

            Console.WriteLine(studentStack.Min().Name);

            var intStack = new CustomStack<int>();

            intStack.Push(4);
            intStack.Push(5);
            intStack.Push(14);
            intStack.Push(42);
            intStack.Push(455);

            intStack.Pop();
            intStack.Pop();

            Console.WriteLine(intStack.Min());

            intStack.Clear();

            Console.WriteLine(intStack.Count);
            Console.WriteLine(intStack.IsEmpty);
            Console.WriteLine(intStack);
        }
Example #4
0
        public void PushPop_CorrectWork()
        {
            CustomStack <int> stack = new CustomStack <int>();

            stack.Push(1);
            stack.Push(2);
            Assert.AreEqual(2, stack.Pop());
            Assert.AreEqual(1, stack.Pop());
        }
Example #5
0
    public void CloseAll()
    {
        for (int i = 0; i < menuStack.Count; i++)
        {
            var instance = menuStack.Pop();

            instance.gameObject.SetActive(false);
        }
    }
        public void TestCountAfterPop()
        {
            customStack.Push(10);
            Assert.AreEqual(1, customStack.Count,
                            "customStack.Count is not equal to 1 after pushing one element");

            customStack.Pop();
            Assert.AreEqual(0, customStack.Count,
                            "customStack.Count is not equal to 0 after pushing one element and then pop it");
        }
        static void Main(string[] args)
        {
            using (reader = File.OpenText("input.txt"))
                using (writer = new StreamWriter(File.Create("output.txt")))
                {
                    int n = reader.ReadInt();
                    CustomStack <char> stack = new CustomStack <char>(10001);
                    while (n > 0)
                    {
                        stack.Clear();
                        string str   = reader.ReadToken();
                        bool   right = true;
                        for (int i = 0; i < str.Length && right; i++)
                        {
                            switch (str[i])
                            {
                            case '(':
                            case '[':
                                stack.Push(str[i]);
                                break;

                            case ')':
                                if (stack.IsEmpty())
                                {
                                    right = false;
                                }
                                else
                                {
                                    char c = stack.Pop();
                                    right = (c == '(');
                                }
                                break;

                            case ']':
                                if (stack.IsEmpty())
                                {
                                    right = false;
                                }
                                else
                                {
                                    char c = stack.Pop();
                                    right = (c == '[');
                                }
                                break;
                            }
                        }

                        right = right && stack.IsEmpty();

                        writer.WriteLine(right ? "YES" : "NO");
                        n--;
                    }
                }
        }
Example #8
0
        public void WhenPushIsCalled_AnItemIsAdded()
        {
            var stack = new CustomStack <int>();

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

            Assert.AreEqual <int>(3, stack.Pop());
            Assert.AreEqual <int>(2, stack.Pop());
            Assert.AreEqual <int>(1, stack.Pop());
        }
Example #9
0
        public void PopShouldReturn60AndDecrementTheCounter()
        {
            //Arrange
            var expectedResult  = 60;
            var expectedCounter = stack.Count - 1;
            //Act
            var actualResult  = stack.Pop();
            var actualCounter = stack.Count;

            //Assert
            Assert.AreEqual(expectedResult, actualResult);
            Assert.AreEqual(expectedCounter, actualCounter);
        }
Example #10
0
        public static void Main()
        {
            CustomStack<int> bsd = new CustomStack<int>();
            bsd.Push(5);
            bsd.Push(3);
            bsd.Push(1);
            Console.WriteLine(bsd.Peek());
            Console.WriteLine(bsd.Pop());

            int[] arr = bsd.ToArray();

            Console.WriteLine(bsd.Pop());
        }
Example #11
0
        static void Main(string[] args)
        {
            ICustomStack<int> sample = new CustomStack<int>();

            sample.Push(1);
            sample.Push(2);
            sample.Push(3);

            Console.WriteLine(sample.Pop() + " pop");
            Console.WriteLine(sample.Pop() + " pop");
            Console.WriteLine(sample.Peek() + " peek");
            Console.WriteLine(sample.Pop() + " pop");
        }
        public void StackPopSeveralElementsWorkCorrectly()
        {
            var stack = new CustomStack <int>();

            stack.Push(5);
            stack.Push(3);
            stack.Push(9);
            stack.Pop();
            var lastElement = stack.Pop();

            Assert.Equal(3, lastElement);
            Assert.Equal(1, stack.Count);
        }
Example #13
0
        public void StackPushPopTest()
        {
            var stack = new CustomStack <int>(20);

            stack.Push(5);
            stack.Push(20);
            Assert.AreEqual(20, stack.Pop());
            stack.Push(500);
            stack.Push(20);
            Assert.AreEqual(20, stack.Pop());
            Assert.AreEqual(500, stack.Pop());
            Assert.AreEqual(5, stack.Pop());
        }
Example #14
0
    private void TryActivateCurrentControlHandler(BaseProjectileControlHandler previousControlHandler)
    {
        _currentBaseProjectileControlHandler = _controlHandlers.Peek();

        while (_currentBaseProjectileControlHandler != null &&
               !_currentBaseProjectileControlHandler.TryActivate(previousControlHandler))
        {
            previousControlHandler = _controlHandlers.Pop();
            Logger.Info("Popped handler: " + previousControlHandler.ToString());
            previousControlHandler.Dispose();

            _currentBaseProjectileControlHandler = _controlHandlers.Peek();
        }
    }
Example #15
0
    private void CommandDispatcher()
    {
        string input = reader.ReadLine();

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

            switch (command)
            {
            case "Push":
                string[] elements = data.Skip(1).ToArray();
                foreach (var element in elements)
                {
                    stack.Push(element);
                }
                break;

            case "Pop":
                stack.Pop();
                break;

            default:
                throw new ArgumentException("Wrong command!");
            }

            input = reader.ReadLine();
        }
    }
Example #16
0
    static void Main()
    {
        var myStack = new CustomStack <int>();

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

                switch (commandType)
                {
                case "Push":
                    int[] args = commandArgs.Skip(1).Select(int.Parse).ToArray();
                    myStack.Push(args);
                    break;

                case "Pop":
                    myStack.Pop();
                    break;
                }
            }

            myStack.Print();
            myStack.Print();
        }
        catch (ArgumentException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
Example #17
0
    public static void Main(string[] args)
    {
        var input = Console.ReadLine();

        var stack = new CustomStack <string>();

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

            if (inputCommand[0] == "Push")
            {
                stack.Push(inputCommand.Skip(1).ToArray());
            }
            else
            {
                stack.Pop();
            }

            input = Console.ReadLine();
        }

        for (int i = 0; i < 2; i++)
        {
            foreach (var element in stack.Reverse())
            {
                Console.WriteLine($"{element}");
            }
        }
    }
Example #18
0
    static void Main(string[] args)
    {
        string input = string.Empty;
        CustomStack <string> stack = new CustomStack <string>();

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

            string command = commandArgs[0];

            switch (command)
            {
            case "Push":
                stack.Push(commandArgs.Skip(1).ToList());
                break;

            case "Pop":
                string element = stack.Pop();
                if (element == null)
                {
                    Console.WriteLine("No elements");
                }
                break;
            }
        }

        if (stack.Count > 0)
        {
            Console.WriteLine(string.Join(Environment.NewLine, stack));
        }
    }
Example #19
0
    public static void Main()
    {
        CustomStack <int> customStack = new CustomStack <int>();

        string input = Console.ReadLine();

        while (input != "END")
        {
            string[] parts   = input.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            string   command = parts[0];
            switch (command)
            {
            case "Push":
                customStack.Push(parts.Skip(1).Select(int.Parse).ToArray());
                break;

            case "Pop":
                customStack.Pop();
                break;
            }
            input = Console.ReadLine();
        }

        foreach (int num in customStack)
        {
            Console.WriteLine(num);
        }
    }
Example #20
0
        public bool UndoDelete()
        {
            bool result = false;

            if (UndoDeleteCount == 0)
            {
                throw new InvalidOperationException("There are no items to be undeleted");
            }

            // Get the item to be undeleted
            MatrixTask matrixTask = _UndoDeleteStack.Pop();

            // Set the MatrixTaskId to 0 (like a new item)
            matrixTask.MatrixTaskId = 0;

            _Context.MatrixTasks.Add(matrixTask);

            try
            {
                this.SaveChanges();
                result = true;
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
        private IEvent _Undo(bool countNonActionable = true) // TODO
        {
            IEvent e = allEvents.Pop();                      // Make method for this

            if (e is IActionableEvent)
            {
                IBaseCommand undoCommand = (e as IActionableEvent).NewUndoCommand();
                if (undoCommand is IEntityModifier)
                {
                    IEntityModifier m = (undoCommand as IEntityModifier);
                    Assert.IsTrue(m is IEventProducing);
                    (m as IEventProducing).DontRecordEvent = true;
                    EM.ApplyMod(m);
                }
                else if (undoCommand is IIndependentModifier)
                {
                    IIndependentModifier m = (undoCommand as IIndependentModifier);
                    Assert.IsTrue(m is IEventProducing);
                    (m as IEventProducing).DontRecordEvent = true;
                    EM.ApplyMod(m);
                }
                else if (undoCommand is Command)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    throw new Exception("Cannot apply undo command: " + undoCommand.GetType().Name);
                }
            }

            return(e);
        }
    public static void Main()
    {
        var customStack = new CustomStack <int>();

        string input;

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

            switch (currentCommand)
            {
            case "Push":
                customStack.Push(tokens.Skip(1).Select(int.Parse).ToArray());
                break;

            case "Pop":
                customStack.Pop();
                break;
            }
        }
        Console.WriteLine(customStack);
    }
Example #23
0
    public static void Main(string[] args)
    {
        var input       = Console.ReadLine();
        var customStack = new CustomStack <string>();

        while (input != "END")
        {
            var separated = input.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            try
            {
                switch (separated[0])
                {
                case "Push":
                    var toBePushed = separated.Skip(1).ToArray();
                    customStack.Push(toBePushed);
                    break;

                case "Pop":
                    customStack.Pop();
                    break;
                }
            }
            catch (Exception ae)
            {
                Console.WriteLine(ae.Message);
            }
            input = Console.ReadLine();
        }

        foreach (var item in customStack)
        {
            Console.WriteLine(item);
        }
    }
        public void GivenStack_AddingAndPopping_ShouldReturnCorrespondingAnswer()
        {
            var stack = new CustomStack(3);

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

            var result = stack.Pop();

            Assert.IsTrue(result == 3);

            result = stack.Pop();
            Assert.IsTrue(result == 2);

            result = stack.Pop();
            Assert.IsTrue(result == 1);
        }
        static void Main(string[] args)
        {
            using (reader = File.OpenText("input.txt"))
                using (writer = new StreamWriter(File.Create("output.txt")))
                {
                    int m = reader.ReadInt();
                    CustomStack <int> stack = new CustomStack <int>(m);
                    for (int i = 0; i < m; i++)
                    {
                        string cmd = reader.ReadToken();
                        switch (cmd)
                        {
                        case "-":
                            writer.Write(stack.Pop());
                            writer.WriteLine();
                            break;

                        case "+":
                            int value = reader.ReadInt();
                            stack.Push(value);
                            break;
                        }
                    }
                }
        }
        public static void Show()
        {
            CustomStack <string> stack = new CustomStack <string>();

            foreach (var item in "A-B-C-D-E-F-G".Split("-"))
            {
                stack.Push(item);
            }

            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(stack.Pop());
                Console.WriteLine(stack.Peek());
                // Console.WriteLine(stack.Pop());
            }



            #region LinkedList
            LinkedList <string>     link  = new LinkedList <string>();
            LinkedListNode <string> node1 = new LinkedListNode <string>("E1");
            LinkedListNode <string> node2 = new LinkedListNode <string>("E2");
            LinkedListNode <string> node3 = new LinkedListNode <string>("E3");
            LinkedListNode <string> node4 = new LinkedListNode <string>("E4");


            link.AddFirst(node1);
            link.AddAfter(node1, node2);
            link.AddAfter(node2, node3);
            link.AddAfter(node3, node4);

            //3.计算包含的数量
            Console.WriteLine(link.Count);

            //4.显示
            LinkedListNode <string> current = link.First;
            while (current != null)
            {
                Console.WriteLine(current.Value);
                current = current.Next;
            }

            //5.查找
            LinkedListNode <string> temp = link.Find("jiajia2");
            if (temp != null)
            {
                Console.WriteLine("找到这个节点" + temp.Value);
            }

            //6.定位最后节点
            temp = link.Last;
            Console.WriteLine("最后这个节点" + temp.Value);

            //7.一些删除操作
            link.RemoveFirst();
            link.Remove("jiajia2");
            link.Clear();
            #endregion
        }
        public void StackPopElementCorrectly()
        {
            var stack = new CustomStack <int>();

            stack.Push(5);
            stack.Pop();
            Assert.Equal(0, stack.Count);
        }
        public void EmptyPop_Test()
        {
            // ARRANGE
            var stack = new CustomStack <int>();

            // ACT
            stack.Pop();
        }
        public void GivenStackAndValuesIncrementGreaterThanStackSize_Increment_IncrementAllStackValues()
        {
            var stack = new CustomStack(3);

            stack.Push(1); stack.Push(2); stack.Push(3);
            stack.Increment(3, 5);

            var result = stack.Pop();

            Assert.IsTrue(result == 8);

            result = stack.Pop();
            Assert.IsTrue(result == 7);

            result = stack.Pop();
            Assert.IsTrue(result == 6);
        }
Example #30
0
 void CheckExitScope(ParserRuleContext context)
 {
     if (IsScopeRule(context))
     {
         listener.depthTables.Pop();
         traverserChildsCounts.Pop();
     }
 }
        public void GivenEmptyStack_Pop_ShouldReturnMinus1()
        {
            var stack = new CustomStack(3);

            var result = stack.Pop();

            Assert.IsTrue(result == -1);
        }
        public void GivenStackAndValuesIncrementSmallerThanCurrentStackSize_Increment_IncrementCorrectStackValues()
        {
            var stack = new CustomStack(3);

            stack.Push(1); stack.Push(2); stack.Push(3);
            stack.Increment(2, 5);

            var result = stack.Pop();

            Assert.IsTrue(result == 3);

            result = stack.Pop();
            Assert.IsTrue(result == 7);

            result = stack.Pop();
            Assert.IsTrue(result == 6);
        }
Example #33
0
        public void Pop_CountDecrease()
        {
            CustomStack <int> stack = new CustomStack <int>();

            stack.Push(1);
            stack.Push(2);
            stack.Pop();
            Assert.AreEqual(1, stack.Count);
        }
Example #34
0
    /* Task 12: 
     * Implement the ADT stack as auto-resizable array. 
     * Resize the capacity on demand (when no space is available to add / insert a new element).
     */

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

        for (int i = 1; i <= 100; i++)
        {
            stackArray.Push(i);
        }

        Console.WriteLine("Total Elements Count : {0}", stackArray.Count());
        stackArray.Push(999);
        Console.WriteLine("Total Elements Count : {0}", stackArray.Count());
        Console.WriteLine(stackArray.Pop());
        Console.WriteLine(stackArray.Pop());
        Console.WriteLine(stackArray.Pop());
        Console.WriteLine(stackArray.Pop());
        Console.WriteLine("Total Elements Count : {0}", stackArray.Count());
    }
Example #35
0
        public static void Main()
        {
            var stack = new CustomStack<int>();
            new List<int> { 1, 2, 3, 4, 5 }.ForEach(x => stack.Push(x));

            while (stack.Count > 0)
            {
                Console.WriteLine(stack.Pop());
            }
        }
        public void Pop_ItemsInStack_ShouldReturnLastPushedItem_ByReference()
        {
            var items = new CustomStack<StringBuilder>();
            var stringBuilder1 = new StringBuilder("Text");
            var stringBuilder2 = new StringBuilder("Another text");

            items.Push(stringBuilder1);
            items.Push(stringBuilder2);

            var builder = items.Pop();

            Assert.AreSame(stringBuilder2, builder);
        }
        static void Main()
        {
            var stack = new CustomStack<int>();

            var studentStack = new CustomStack<Student>();

            studentStack.Push(new Student("Pesho", 12));
            studentStack.Push(new Student("Gosho", 22));
            studentStack.Push(new Student("Minka", 23));
            studentStack.Push(new Student("Stamat", 45));
            studentStack.Push(new Student("Kiril", 33));

            Console.WriteLine(studentStack.Min().Name);

            stack.Push(4);
            stack.Push(3);
            stack.Push(44);
            stack.Push(31);
            stack.Push(12);
            stack.Push(8);

            stack.Pop();
            stack.Pop();

            Console.WriteLine(stack);
            Console.WriteLine(stack.Count);
            Console.WriteLine(stack.IsEmpty);
            Console.WriteLine(stack.Contains(4));
            Console.WriteLine(stack.Contains(111));

            Console.WriteLine(stack.Min());

            stack.Clear();

            Console.WriteLine(stack);
            Console.WriteLine(stack.Count);
            Console.WriteLine(stack.IsEmpty);
        }
        public static void Main()
        {
            CustomStack<int> numbers = new CustomStack<int>();

            numbers.Push(5);
            numbers.Push(6);
            numbers.Push(2);
            numbers.Push(7);
            numbers.Push(8);

            Console.WriteLine(string.Join(", ",numbers));
            Console.WriteLine(numbers.Pop());
            Console.WriteLine(string.Join(", ", numbers));
        }
        public static void Main()
        {
            var stack = new CustomStack<int>();

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

            while (stack.Count > 0)
            {
                Console.WriteLine(stack.Pop());
            }
        }
 public static void Execute()
 {
     CustomStack<string> stack = new CustomStack<string>();
        stack.Push(new linkedNode<string>("first"));
        stack.Push(new linkedNode<string>("second"));
        stack.Push(new linkedNode<string>("third"));
        stack.Traverse();
        Console.WriteLine("now try to peek");
        Console.WriteLine(stack.Peek().Data);
        Console.WriteLine("traverse again");
        stack.Traverse();
        Console.WriteLine("now try to pop");
        Console.WriteLine(stack.Pop().Data);
        Console.WriteLine("traverse again");
        stack.Traverse();
        Console.WriteLine("pop two more and traverse again");
        stack.Pop(); stack.Pop(); stack.Traverse();
        Console.WriteLine("push the items back and traverse again");
        stack.Push(new linkedNode<string>("first"));
        stack.Push(new linkedNode<string>("second"));
        stack.Push(new linkedNode<string>("third"));
        stack.Traverse();
 }
        static void Main()
        {
            var testCustomStack = new CustomStack<int>();
            for (int i = 0; i < 10; i++)
            {
                testCustomStack.Push(i + 1);
            }

            Console.WriteLine("Stack size: {0}", testCustomStack.Count);

            while (testCustomStack.Count > 0)
            {
                Console.WriteLine("Stack current top element: {0}", testCustomStack.Pop());
            }
        }
        public static void Main(string[] args)
        {
            var stack = new CustomStack<int>();

            stack.Push(50);
            stack.Push(3);
            stack.Push(56);
            stack.Push(50);
            stack.Push(3);
            stack.Push(56);
            stack.Push(50);
            stack.Push(3);
            stack.Push(56);
            stack.Push(50);
            stack.Push(3);
            stack.Push(56);

            Console.WriteLine(stack.Peek());
            stack.Pop();
            var a = stack.Pop();
            Console.WriteLine(a);

            Console.WriteLine(stack.Contains(56));
        }
Example #43
0
        public void CustomStack_StackPopTest()
        {
            var actual = new CustomStack<int>();
            for (int i = 0; i < 10; i++)
            {
                actual.Push(i);
            }
            for (int i = 0; i < 5; i++)
            {
                actual.Pop();
            }
            const int expected = 5;

            Assert.AreEqual(actual.Count, expected);
        }
Example #44
0
    static void Main(string[] args)
    {
        CustomStack<int> customStack = new CustomStack<int>();

        customStack.Push(123);
        customStack.Push(124);
        customStack.Push(125);
        customStack.Push(1251);

        Console.WriteLine("Stack count: {0}", customStack.Count);

        int number = customStack.Pop();
        Console.WriteLine("Pop an element: {0}", number);
        Console.WriteLine("Peek element: {0}", customStack.Peek());
    }
Example #45
0
        public static void Main(string[] args)
        {
            var stack = new CustomStack<string>();

            stack.Push("pesho");
            stack.Push("gosho");
            stack.Push("vankata");

            Console.WriteLine(stack.Peek());
            Console.WriteLine(stack);

            var popedElement = stack.Pop();
            Console.WriteLine(popedElement);
            Console.WriteLine(stack);
        }
Example #46
0
 static void Main(string[] args)
 {
     CustomStack<int> stack = new CustomStack<int>();
     stack.Push(3);
     stack.Push(6);
     stack.Push(11);
     stack.Push(91);
     stack.Push(31);
     Console.WriteLine(stack.Peek());
     Console.WriteLine(stack.Peek());
     Console.WriteLine(stack.Peek());
     stack.Push(1001);
     Console.WriteLine(stack.Peek());
     Console.WriteLine(stack.Pop());
     Console.WriteLine(stack.Peek());
 }
        public void CustomStack_StackPopTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            for (int i = 0; i < 5; i++)
            {
                myStack.Pop();
            }

            int expected = 5;

            Assert.AreEqual(expected, myStack.Count);
        }
        public void CustomStack_AccurateStackPopTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();
            List<int> actual = new List<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            for (int i = 0; i < 5; i++)
            {
                actual.Add(myStack.Pop());
            }

            List<int> expected = new List<int>() { 9, 8, 7, 6, 5 };

            CollectionAssert.AreEqual(expected, actual);
        }
    public static void Execute()
    {
        BSTree<int> tree = new BSTree<int>();

        tree.Insert(new BSTNode<int>(5));
        tree.Insert(new BSTNode<int>(10));
        tree.Insert(new BSTNode<int>(8));
        tree.Insert(new BSTNode<int>(20));
        tree.Insert(new BSTNode<int>(2));
        tree.Insert(new BSTNode<int>(100));
        tree.Insert(new BSTNode<int>(1));
        tree.Insert(new BSTNode<int>(3));
        tree.Insert(new BSTNode<int>(80));
        tree.Insert(new BSTNode<int>(7));
        tree.Insert(new BSTNode<int>(19));
        tree.Insert(new BSTNode<int>(9));
        tree.Insert(new BSTNode<int>(110));

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

        stack.Push(new linkedNode<BSTNode<int>>(tree.root));

        while (stack.head != null)
        {
            BSTNode<int> cursor = stack.Pop().Data;
            if (cursor == null)
                break;
            Console.WriteLine(cursor.Data);
            BSTNode<int> n = cursor.right;
            if (n != null)
                stack.Push(new linkedNode<BSTNode<int>>(n));
            n = cursor.left;
            if(n!=null)
                stack.Push(new linkedNode<BSTNode<int>>(n));

        }

        stack.Traverse();
    }
Example #50
0
        public void CustomStack_StackEmptyPushTest()
        {
            var actual = new CustomStack<int>();

            actual.Pop();
        }
        public void CustomStack_InvalidEmptyStackPopTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();

            myStack.Pop();
        }