static void Main()
        {
            var myStack = new MyStack<int>();
            myStack.Push(1);
            myStack.Push(2);
            myStack.Push(3);
            myStack.Push(5);

            foreach (var n in myStack)
            {
                Console.WriteLine(n); // 5 3 2 1
            }
            Console.WriteLine("Stack size: " + myStack.Count); // 4
            Console.WriteLine();

            Console.WriteLine("Peek number: " + myStack.Peek); // 5
            Console.WriteLine();

            Console.WriteLine("Pop the upper number");
            Console.WriteLine(myStack.Pop());
            Console.WriteLine();

            Console.WriteLine("New upper number");
            Console.WriteLine(myStack.Peek); //1
            Console.WriteLine();

            Console.WriteLine("Stack size: " + myStack.Count);
        }
        public void TopTest()
        {
            MyStack<int> stack = new MyStack<int>();
            stack.Push(10);

            Assert.IsTrue(stack.Top() == 10, "10");
        }
        public void PushTest()
        {
            MyStack<int> stack = new MyStack<int>();
            stack.Push(10);

            Assert.IsFalse(stack.Empty());
        }
Esempio n. 4
0
        static void Main()
        {
            MyStack<int> numbers = new MyStack<int>();
            for (int i = 0; i < 20; i++)
            {
                numbers.Push(i);
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Deleted from stack - {0}", numbers.Pop());
            }

            // Display the stack
            foreach (var number in numbers)
            {
                Console.WriteLine(number);
            }

            numbers.Clear();
            try
            {
                Console.WriteLine("Peek at top element: ");
                numbers.Peek();
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }

            
        }
Esempio n. 5
0
        public StackForm()
        {
            InitializeComponent();

            ms = new MyStack<string>();
            rand = new Random();
        }
Esempio n. 6
0
 /// <summary>
 /// Sorts the droids based on model
 /// </summary>
 /// <param name="toSort"></param>
 public void SortModel(List<Droid> toSort)
 {
     MyStack<UtilityDroid> utilityStack = new MyStack<UtilityDroid>();
     MyStack<AstromechDroid> astroStack = new MyStack<AstromechDroid>();
     MyStack<ProtocolDroid> protoStack = new MyStack<ProtocolDroid>();
     MyStack<JanitorDroid> janitorStack = new MyStack<JanitorDroid>();
     //Separates the List based on class
     foreach (Droid d in toSort)
     {
         if (d is AstromechDroid)
             astroStack.Add((AstromechDroid)d);
         else if (d is JanitorDroid)
             janitorStack.Add((JanitorDroid)d);
         else if (d is UtilityDroid)
             utilityStack.Add((UtilityDroid)d);
         else if (d is ProtocolDroid)
             protoStack.Add((ProtocolDroid)d);
     }
     // puts the stacks into a Queue
     MyQueue<Droid> tmpQue = new MyQueue<Droid>();
     while (astroStack.Count > 0)
         tmpQue.Add(astroStack.Get());
     while (janitorStack.Count > 0)
         tmpQue.Add(janitorStack.Get());
     while (utilityStack.Count > 0)
         tmpQue.Add(utilityStack.Get());
     while (protoStack.Count > 0)
         tmpQue.Add(protoStack.Get());
     //Relies on the fact that a list is a reference object
     toSort.Clear();
     while (tmpQue.Count > 0)
         toSort.Add(tmpQue.Get());
 }
Esempio n. 7
0
        public static void Main()
        {
            MyStack<int> testStack = new MyStack<int>();

            //test Push
            testStack.Push(2);
            testStack.Push(3);
            testStack.Push(4);
            testStack.Push(5);
            testStack.Print();

            //test auto-resize
            testStack.Push(6);
            testStack.Print();

            //test Pop
            Console.WriteLine(testStack.Pop());
            Console.WriteLine(testStack.Pop());
            Console.WriteLine(testStack.Pop());
            testStack.Print();

            //test Peek
            Console.WriteLine(testStack.Peek());
            testStack.Pop();
            Console.WriteLine(testStack.Peek());
        }
        public void ConvertDecimalToBaseTest()
        {
            MyStack<string> result = new MyStack<string>();
            MathExtension.ConvertDecimalToBase(ref result, 100, 5);

            Assert.IsFalse(result.Empty());
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            MyStack<int> myIntStack = new MyStack<int>(5);

            try
            {
                myIntStack.Push(1);
                myIntStack.Push(2);
                myIntStack.Push(3);
                myIntStack.Push(4);
                myIntStack.Push(5);
                myIntStack.Push(6);
            }
            catch (MyStackIsFullException e)
            {
                Console.WriteLine(e.Message);
            }

            try
            {
                Console.WriteLine(myIntStack.Pop());
                Console.WriteLine(myIntStack.Pop());
                Console.WriteLine(myIntStack.Pop());
                Console.WriteLine(myIntStack.Pop());
                Console.WriteLine(myIntStack.Pop());
                Console.WriteLine(myIntStack.Pop());
            }
            catch (MyStackIsEmptyException e)
            {
                Console.WriteLine(e.Message);
            }

            MyStack<Circle> myCircleStack = new MyStack<Circle>(5);

            try
            {
                myCircleStack.Push(new Circle(5));
                myCircleStack.Push(new Circle(3));
                myCircleStack.Push(new Circle(2));
            }
            catch (MyStackIsFullException e)
            {
                Console.WriteLine(e.Message);
            }

            try
            {
                var c = myCircleStack.Pop();
                Console.WriteLine(c);
                Console.WriteLine(myCircleStack.Pop());
                Console.WriteLine(myCircleStack.Pop());
            }
            catch (MyStackIsEmptyException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }
Esempio n. 10
0
 static void Main(string[] args)
 {
     MyStack<int> stack = new MyStack<int>();
     stack.Push(9);
     stack.Push(10);
     stack.Pop();
     Console.WriteLine(stack.Contains(10));
 }
Esempio n. 11
0
        public void Count_EmptyStack_ReturnZero()
        {
            MyStack<string> stack = new MyStack<string>();

            int expected = 0;
            int actual = stack.Count();

            Assert.AreEqual(expected, actual, "Count fail empty stack");
        }
        public void should_get_is_empty_for_my_stack()
        {
            var myStack = new MyStack();
            myStack.Push(2);
            Assert.False(myStack.IsEmpty());

            myStack.Pop();
            Assert.True(myStack.IsEmpty());
        }
Esempio n. 13
0
        public void AddRefTypeItemToStack()
        {
            String value = "Hello World";

            MyStack<String> stack = new MyStack<String>();
            stack.Push(value);

            String result = stack.Pop();

            Assert.AreEqual(result, value, "Pop value is incorrect");
        }
Esempio n. 14
0
        public void AddValueTypeItemToStack()
        {
            int value = 12345;

            MyStack<int> stack = new MyStack<int>();
            stack.Push(value);

            int result = stack.Pop();

            Assert.AreEqual(result, value, "Pop value is incorrect");
        }
Esempio n. 15
0
        public void Count_UseToHaveItem_ReturnZero()
        {
            MyStack<string> stack = new MyStack<string>();

            int expected = 0;
            stack.Push("aaa");
            stack.Push("bbb");
            stack.Pop();
            stack.Pop();
            int actual = stack.Count();

            Assert.AreEqual(expected, actual, "Count fail on use to have item stack");
        }
Esempio n. 16
0
        public void PushTest()
        {
            int           capacity = 2;                           // TODO: Initialize to an appropriate value
            MyStack <int> target   = new MyStack <int>(capacity); // TODO: Initialize to an appropriate value

            target.Push(1);
            target.Push(2);
            target.Push(3);
            target.Push(4);
            target.Push(5);
            target.Push(6);
            //Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
 public static void Main()
 {
     MyStack<int> myStack = new MyStack<int>();
     myStack.Push(1);
     myStack.Push(2);
     myStack.Push(3);
     myStack.Push(4);
     myStack.Push(5);
     myStack.Push(6);
     myStack.Push(7);
     myStack.Push(8);
     myStack.Push(9);
     Console.WriteLine(string.Join(", ", myStack.Array));
 }
Esempio n. 18
0
        public void Count_HaveItem_ReturnItemCount()
        {
            MyStack<string> stack = new MyStack<string>();
            Random rand = new Random();

            int expected = rand.Next(1, 10000);
            for (int i = 0; i < expected; i++)
            {
                stack.Push("aaa");
            }
            int actual = stack.Count();

            Assert.AreEqual(expected, actual, "Count fail on have item stack");
        }
Esempio n. 19
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Adapter Mode Demo");

            var myStack = new MyStack <string>();

            myStack.Push("First String");
            myStack.Push("Second String");
            myStack.Push("Third String");

            myStack.Pop();

            myStack.PrintAll();
        }
Esempio n. 20
0
        static void main(string[] args)
        {
            // int[,] arr = { {0,1,1,1} , {1,0,1,0} , {0,0,0,1} , {1,1,1,0} } ;

            // CelebrityProblem(arr);

            MyStack ms = new MyStack();

            ms.Push(20);
            ms.Push(30);
            ms.Push(5);
            Console.WriteLine(ms.Min());
            ms.Push(2);
            Console.WriteLine(ms.Peek());
        }
Esempio n. 21
0
        public void Count_AfterPop_LessOne()
        {
            MyStack<string> stack = new MyStack<string>();

            stack.Push("aaa");
            stack.Push("bbb");
            stack.Push("ccc");

            stack.Pop();

            int expected = 2;
            int actual = stack.Count();

            Assert.AreEqual(expected, actual, "Count fail on after pop stack");
        }
Esempio n. 22
0
        public void pop_elem()
        {
            MyStack <float> stack = new MyStack <float>();
            float           x     = 10.0f;
            float           y     = 18.0f;
            float           z     = 50.0f;

            stack.Push(x);
            stack.Push(y);
            stack.Push(z);

            Assert.AreEqual(z, stack.Pop());
            Assert.AreEqual(y, stack.Pop());
            Assert.AreEqual(x, stack.Pop());
        }
Esempio n. 23
0
    static void Main()
    {
        MyStack <int>    StackInt    = new MyStack <int>();
        MyStack <string> StackString = new MyStack <string>();

        StackInt.Push(3);
        StackInt.Push(4);
        StackInt.Push(5);
        StackInt.Push(6);
        StackInt.Print();

        StackString.Push("Wheels Are Awesome!");
        StackString.Push("20180620");
        StackString.Print();
    }
Esempio n. 24
0
        public void Pop_HaveItem_RemoveLastOne()
        {
            MyStack <string> stack = new MyStack <string>();

            stack.Push("aaa");
            stack.Push("bbb");
            stack.Push("ccc");

            stack.Pop();

            string expected = "bbb";
            string actual   = stack.Peek();

            Assert.AreEqual(expected, actual, "Pop fail on have item stack");
        }
Esempio n. 25
0
    static void Main()
    {
        MyStack <int>    StackInt    = new MyStack <int>();
        MyStack <string> StackString = new MyStack <string>();

        StackInt.Push(3);
        StackInt.Push(5);
        StackInt.Push(7);
        StackInt.Push(9);
        StackInt.Print();

        StackString.Push("This is fun");
        StackString.Push("Hi there! ");
        StackString.Print();
    }
Esempio n. 26
0
        static void Main(string[] args)
        {
            var stack = new MyStack<int>();
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            stack.Push(4);
            stack.Push(5);

            Console.WriteLine(stack.ToString());
            Console.WriteLine(stack.Capacity);
            Console.WriteLine(stack.Count);
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Peek());
        }
Esempio n. 27
0
        public void Peek_HaveItem_NotDeleteLastItem()
        {
            MyStack <string> stack = new MyStack <string>();

            stack.Push("aaa");
            stack.Push("bbb");
            stack.Push("ccc");

            stack.Peek();

            string expected = "ccc";
            string actual   = stack.Peek();

            Assert.AreEqual(expected, actual, "Peek fail on have item stack");
        }
Esempio n. 28
0
        //tested
        public MyQueue <int> ReverseQueue(MyQueue <int> queue)
        {
            MyStack <int> tempStack = new MyStack <int>();
            MyQueue <int> result    = new MyQueue <int>();

            while (!queue.IsEmpty())
            {
                tempStack.Push(queue.Remove());
            }
            while (!tempStack.IsEmpty())
            {
                result.Insert(tempStack.Pop());
            }
            return(result);
        }
Esempio n. 29
0
 public KhachHangUC(SqlConnection kn, string branchCode, UpdateInterface infForm, MyStack mystack)
 {
     InitializeComponent();
     this.kn      = kn;
     this.infForm = infForm;
     this.mystack = mystack;
     //if (atype == AppType.Edit)
     //{
     this.Text   = "Thêm thông tin Khách Hàng";
     addBtn.Text = "Thêm";
     //addBtn.Enabled = true;
     this.clientCode = branchCode;
     string     str = "exec sp_getKhachHang";
     SqlCommand com = new SqlCommand(str, kn);
 }
Esempio n. 30
0
        public void TestPop()
        {
            // Arrange
            MyStack stack = new MyStack();

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

            // Act
            int top = stack.Pop();

            // Assert
            Assert.AreEqual(top, 3);
            Assert.AreEqual(stack.StackMin(), 2);
        }
Esempio n. 31
0
        public void Count_AfterPeek_NothingChange()
        {
            MyStack <string> stack = new MyStack <string>();

            stack.Push("aaa");
            stack.Push("bbb");
            stack.Push("ccc");

            stack.Peek();

            int expected = 3;
            int actual   = stack.Count();

            Assert.AreEqual(expected, actual, "Count fail on after peek stack");
        }
Esempio n. 32
0
        public void Count_HaveItem_ReturnItemCount()
        {
            MyStack <string> stack = new MyStack <string>();
            Random           rand  = new Random();

            int expected = rand.Next(1, 10000);

            for (int i = 0; i < expected; i++)
            {
                stack.Push("aaa");
            }
            int actual = stack.Count();

            Assert.AreEqual(expected, actual, "Count fail on have item stack");
        }
Esempio n. 33
0
        public void Count_AfterPop_LessOne()
        {
            MyStack <string> stack = new MyStack <string>();

            stack.Push("aaa");
            stack.Push("bbb");
            stack.Push("ccc");

            stack.Pop();

            int expected = 2;
            int actual   = stack.Count();

            Assert.AreEqual(expected, actual, "Count fail on after pop stack");
        }
Esempio n. 34
0
        public void GivenAStack_WhenHaveTwoItems_ShouldReturnTheLastItemAndRemoveFromTheStack()
        {
            // Arrange
            var stack = new MyStack <int>();

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

            // Act
            var item = stack.Pop();

            // Assert
            item.Should().Be(2);
            stack.Size.Should().Be(1);
        }
Esempio n. 35
0
        public void CanPopTopNodeFromStack()
        {
            MyStack <string> stack = new MyStack <string>();
            Node <string>    node1 = new Node <string>("One");
            Node <string>    node2 = new Node <string>("Two");
            Node <string>    node3 = new Node <string>("Three");

            stack.Push(node1);
            stack.Push(node2);
            stack.Push(node3);
            stack.Pop();
            Node <string> top = stack.Peek();

            Assert.Equal("Two", top.Value);
        }
Esempio n. 36
0
        void loadInput(IStatement input)
        {
            System.Console.WriteLine("\n...... LOADING: " + input.ToString() + '\n');
            repo.clearAll();

            IStack <IStatement>   exe_stack   = new MyStack <IStatement>();
            IMap <string, int>    sym_table   = new MyMap <string, int>();
            IMap <int, FileTuple> files_table = new MyMap <int, FileTuple>();
            IList <int>           out_stream  = new MyList <int>();

            exe_stack.push(input);
            PState state = new PState(exe_stack, sym_table, out_stream, files_table);

            repo.addPState(state);
        }
Esempio n. 37
0
        public void CanRecoverDataFromPoppedNode()
        {
            MyStack <string> stack = new MyStack <string>();
            Node <string>    node1 = new Node <string>("One");
            Node <string>    node2 = new Node <string>("Two");
            Node <string>    node3 = new Node <string>("Three");

            stack.Push(node1);
            stack.Push(node2);
            stack.Push(node3);
            stack.Pop();
            Node <string> pop = stack.Pop();

            Assert.Equal("Two", pop.Value);
        }
Esempio n. 38
0
        private void frmDepot_Load(object sender, EventArgs e)
        {
            _buttonAction        = ButtonActionType.None;
            _userDo              = new MyStack();
            _userDo.StackPushed += userDo_StackPushed;
            _userDo.StackPopped += userDo_StackPopped;

            LoadTable();
            DisableEditMode();

            _currentDeploymentId = ((DataRowView)bdsDepot[0])["MACN"].ToString().Trim();

            // Quyền công ty => enable combobox chi nhánh
            ShowControlsByGroup(UtilDB.CurrentGroup);
        }
Esempio n. 39
0
        public void TestModifiers()
        {
            MyStack <string> st = new MyStack <string>();

            st.Push("dunk");
            st.Push("shpee");
            Assert.AreEqual(st.Pop(), "shpee");
            Assert.AreEqual(st.Pop(), "dunk");
            st.Push("1");
            st.Push("2");
            st.Push("3");
            Assert.AreEqual(st.Size(), 3);
            st.Flush();
            Assert.AreEqual(st.IsEmpty(), true);
        }
        public static void Main()
        {
            var testStack = new MyStack<int>();

            for (int i = 0; i < 10; i++)
            {
                testStack.Push((i + 1) * 5);
                Console.WriteLine("At position {0}. is inserted {1}", i, testStack.Peek());
            }

            var lastElement = testStack.Pop();
            Console.WriteLine("{0} was removed from the stack", lastElement);

            Console.WriteLine("The number of elemnents in the satck is {0} and last one is {1}", testStack.Count, testStack.Peek());
        }
Esempio n. 41
0
        public void StackPush3ItemAndPop3GetCountAndIsEmpty()
        {
            int maxSize = 100;
            var myStack = new MyStack(maxSize);

            myStack.Push(1);
            myStack.Push("1");
            myStack.Push("A");
            var obj = myStack.Pop();

            obj = myStack.Pop();
            obj = myStack.Pop();
            Assert.AreEqual(1, obj);
            Assert.AreEqual(true, myStack.IsEmpty());
        }
Esempio n. 42
0
        static void Main(string[] args)
        {
            MyStack <int> stack = new MyStack <int>();  //creating an object

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

            while (!stack.IsEmpty)
            {
                int number = stack.Pop();
                Console.WriteLine("Last value popped = {0}", number);
            }

            Console.ReadLine();
        }
Esempio n. 43
0
        public void TestElementCount()
        {
            MyStack <int> stack = new MyStack <int>(3);

            Assert.AreEqual(true, stack.IsEmpty());
            Assert.AreEqual(false, stack.IsFull());

            stack.Push(1);
            Assert.AreEqual(false, stack.IsEmpty());
            Assert.AreEqual(false, stack.IsFull());

            stack.Push(2);
            stack.Push(3);
            Assert.AreEqual(false, stack.IsEmpty());
            Assert.AreEqual(true, stack.IsFull());
        }
        public void Given3NumberInStack_WhenPoped_ShouldReturnEmpty()
        {
            MyNode  myFirstNode  = new MyNode(70);
            MyNode  mySecondNode = new MyNode(30);
            MyNode  myThirdNode  = new MyNode(56);
            MyStack myStack      = new MyStack();

            myStack.Push(myFirstNode);
            myStack.Push(mySecondNode);
            myStack.Push(myThirdNode);
            MyNode pop  = myStack.Pop();
            MyNode pop1 = myStack.Pop();
            MyNode pop2 = myStack.Pop();

            Assert.AreEqual(null, pop2.getNext());
        }
        public void Given3Number_WhenAddedToStack_ShouldHaveLastAddedNode()
        {
            MyNode  myFirstNode  = new MyNode(70);
            MyNode  mySecondNode = new MyNode(30);
            MyNode  myThirdNode  = new MyNode(56);
            MyStack myStack      = new MyStack();

            myStack.Push(myFirstNode);
            myStack.Push(mySecondNode);
            myStack.Push(myThirdNode);
            myStack.PrintStack();
            MyNode peak;

            peak = myStack.Peak();
            Assert.AreEqual(myThirdNode, peak);
        }
Esempio n. 46
0
        public void PeekStackTest()
        {
            var stack = new MyStack <int>();
            var rand  = new Random();
            int last  = 0;

            for (int i = 0; i < 46; i++)
            {
                last = rand.Next(0, 1000);
                stack.Push(last);
            }

            Assert.AreEqual(46, stack.Count);
            Assert.AreEqual(last, stack.Peek());
            Assert.AreEqual(46, stack.Count);
        }
Esempio n. 47
0
        public void PushInStackTwentyElements_PopOneElement_CountEquals19()
        {
            var stack = new MyStack <int>();
            var rand  = new Random();
            int last  = 0;

            for (int i = 0; i < 20; i++)
            {
                last = rand.Next(0, 100);
                stack.Push(last);
            }

            Assert.AreEqual(20, stack.Count);
            Assert.AreEqual(last, stack.Pop());
            Assert.AreEqual(19, stack.Count);
        }
Esempio n. 48
0
        public void TestMyStack()
        {
            var testObj = new MyStack();

            testObj.Push(0);
            testObj.Push(1);
            testObj.Push(2);

            Assert.IsFalse(testObj.Empty());
            Assert.AreEqual(2, testObj.Pop());

            testObj.Push(3);
            Assert.AreEqual(3, testObj.Pop());
            Assert.AreEqual(1, testObj.Pop());
            Assert.AreEqual(0, testObj.Pop());
        }
Esempio n. 49
0
        public void PushInStack46Elements_PeekOneElements_StackCountEquals46()
        {
            var stack = new MyStack <int>();
            var rand  = new Random();
            int last  = 0;

            for (int i = 0; i < 46; i++)
            {
                last = rand.Next(0, 1000);
                stack.Push(last);
            }

            Assert.AreEqual(46, stack.Count);
            Assert.AreEqual(last, stack.Peek());
            Assert.AreEqual(46, stack.Count);
        }
Esempio n. 50
0
    static void Main(string[] args)
    {
        MyStack <int> stack = new MyStack <int>(0);

        stack.Push(11);
        stack.Push(133);
        stack.Push(100);
        stack.Push(8);

        stack.Show();
        stack.Pop();
        stack.Show();
        stack.Clear();
        stack.Show();
        // Check<MyStack<int>>.showArray(stack);
    }
Esempio n. 51
0
 static void Main()
 {
     MyStack<int> myStack = new MyStack<int>();
     myStack.Push(3);
     myStack.Push(5);
     myStack.Push(9);
     myStack.Push(8);
     Console.WriteLine(myStack.Capacity);
     myStack.Push(16);
     myStack.Push(17);
     Console.WriteLine(myStack.Count);
     Console.WriteLine(myStack.Capacity);
     Console.WriteLine(myStack.Peek());
     Console.WriteLine(myStack.Pop());
     Console.WriteLine(myStack.Count);
     Console.WriteLine(myStack.Capacity);
 }
Esempio n. 52
0
    public static void PopAll(MyStack[] stacks)
    {
        if (!stacks.Any() || stacks.Length == 1) return;

        while (true)
        {
            for (var i = 0; i < stacks.Length; i++)
            {
                var curStack = stacks[i];
                if (stacks.Where((v, _i) => _i != i && curStack.Sum > v.Sum).Any())
                {
                    curStack.Pop();
                }
            }

            if (stacks.All(_ => _.Sum == stacks.First().Sum)) break;
        }
    }
Esempio n. 53
0
        static void Main()
        {
            MyStack<int> stack = new MyStack<int>();
            stack.Push(3);
            stack.Push(5);
            stack.Push(15);
            stack.Push(23);
            stack.Push(81);
            stack.Push(100);
            var poped = stack.Pop();
            Console.WriteLine("Pop element {0}", poped);
            Console.WriteLine("Peek element {0}", stack.Peek());

            foreach (var number in stack)
            {
                Console.WriteLine(number);
            }
        }
 static void Main(string[] args)
 {
     var stack = new MyStack<int>();
     stack.Push(1);
     stack.Push(2);
     stack.Push(3);
     Console.WriteLine("Capacity: "+stack.Capacity);
     stack.Push(4);
     stack.Push(5);
     Console.WriteLine("Capacity: "+stack.Capacity);
     Console.WriteLine("-----------------------------");
     foreach (var i in stack)
     {
         Console.WriteLine(i);
     }
     Console.WriteLine("-----------------------------");
     stack.TrimExess();
     Console.WriteLine("Capacity: "+stack.Capacity);
 }
Esempio n. 55
0
        public double Calculate(String expression)
        {
            string[] str = ReversePolishNotation.ConvertToReversePolishNotation(ReversePolishNotation.DeleteSpaces(expression));
            var stack = new MyStack<double>();
            foreach (var s in str)
            {
                double number;
                if (Double.TryParse(s, out number))
                {
                    stack.Push(number);
                }
                else
                {
                    double num1;
                    double num2;
                    switch (s)
                    {
                        case "+":
                            num1 = stack.Pop();
                            num2 = stack.Pop();
                            stack.Push(num1 + num2);
                            break;
                        case "-":
                            num1 = stack.Pop();
                            num2 = stack.Pop();
                            stack.Push(num2 - num1);
                            break;
                        case "*":
                            num1 = stack.Pop();
                            num2 = stack.Pop();
                            stack.Push(num1 * num2);
                            break;
                        case "/":
                            num1 = stack.Pop();
                            num2 = stack.Pop();
                            stack.Push(num2 / num1);
                            break;

                    }
                }
            }
            return stack.Pop();
        }
Esempio n. 56
0
        public static void Main()
        {
            MyStack<int> myStack = new MyStack<int>();
            for (int i = 1; i < 10; i++)
            {
                myStack.Push(i);
            }

            Console.WriteLine("Elements count: {0}", myStack.Count);
            Console.WriteLine("Pop: {0}", myStack.Pop());
            Console.WriteLine("Elements count: {0}", myStack.Count);

            while (myStack.Count > 0)
            {
                Console.WriteLine("Pop: {0}", myStack.Pop());
            }

            Console.WriteLine("Elements count: {0}", myStack.Count);
        }
Esempio n. 57
0
        public static void Main()
        {
            MyStack<int> testStack = new MyStack<int>();

            testStack.Push(1);
            testStack.Push(2);
            testStack.Push(3);
            testStack.Push(1);
            testStack.Push(4);
            testStack.Push(4);
            testStack.Push(2);
            testStack.Push(7);

            Console.WriteLine(testStack);

            Console.WriteLine(testStack.Pop());

            testStack.Push(12);
            Console.WriteLine(testStack);
        }
Esempio n. 58
0
        static void Main()
        {
            MyStack<int> stack = new MyStack<int>();

            // push some elements to test if work correctly
            stack.Push(5);
            stack.Push(10);
            stack.Push(15);
            stack.Push(80);
            stack.Push(-95);

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

            Console.WriteLine(stack.Count);
            Console.WriteLine(stack.Capacity);
            Console.WriteLine();

            // test pop
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine();

            // test contains method
            Console.WriteLine(stack.Contains(-95));
            Console.WriteLine(stack.Contains(10));
            Console.WriteLine();

            // test if count and capacity work correctly after pop elements
            Console.WriteLine(stack.Count);
            Console.WriteLine(stack.Capacity);

            // test toArray and toString
            var stackAsArray = stack.ToArray();
            Console.WriteLine(string.Join(", ", stackAsArray));
            Console.WriteLine(stack.ToString());
        }
Esempio n. 59
0
        public static void Main()
        {
            var stack = new MyStack<int>();
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            stack.Push(4);
            stack.Push(5);
            stack.Push(6);
            stack.Push(7);

            Console.WriteLine(string.Join(", ", stack));

            stack.Pop();
            stack.Pop();
            stack.Pop();
            stack.Pop();
            stack.Push(7);

            Console.WriteLine(string.Join(", ", stack));
        }
Esempio n. 60
-1
        public void Count_AfterPeek_NothingChange()
        {
            MyStack<string> stack = new MyStack<string>();

            stack.Push("aaa");
            stack.Push("bbb");
            stack.Push("ccc");

            stack.Peek();

            int expected = 3;
            int actual = stack.Count();

            Assert.AreEqual(expected, actual, "Count fail on after peek stack");
        }