Пример #1
0
        /* prints element and NGE pair for
        *  all elements of arr[] of size n */
        public static void printNGE(int[] arr, int n)
        {
            int   i = 0;
            stack s = new stack();

            s.top = -1;
            int element, next;

            /* push the first element to stack */
            s.push(arr[0]);

            // iterate for rest of the elements
            for (i = 1; i < n; i++)
            {
                next = arr[i];

                if (s.Empty == false)
                {
                    // if stack is not empty, then
                    // pop an element from stack
                    element = s.pop();

                    /* If the popped element is smaller than
                     * next, then a) print the pair b) keep
                     * popping while elements are smaller and
                     * stack is not empty */
                    while (element < next)
                    {
                        Console.WriteLine(element + " --> "
                                          + next);
                        if (s.Empty == true)
                        {
                            break;
                        }
                        element = s.pop();
                    }

                    /* If element is greater than next, then
                     * push the element back */
                    if (element > next)
                    {
                        s.push(element);
                    }
                }

                /* push next to stack so that we can find next
                 * greater for it */
                s.push(next);
            }

            /* After iterating over the loop, the remaining
             * elements in stack do not have the next greater
             * element, so print -1 for them */
            while (s.Empty == false)
            {
                element = s.pop();
                next    = -1;
                Console.WriteLine(element + " -- " + next);
            }
        }
Пример #2
0
        public void TestPop()
        {
            stack s = new stack(10);

            s.push(3);
            s.push(5);
            s.push(7);
            Assert.AreEqual(7, s.pop());
            Assert.AreEqual(5, s.pop());
        }
Пример #3
0
        public void CanEmptyStacksWithPops()
        {
            stack crayons = new stack();

            crayons.push(5);
            crayons.push(4);
            crayons.pop();
            crayons.pop();

            Assert.Null(crayons.Top);
        }
Пример #4
0
    // Driver program to test above methods
    public static void main(String[] args)
    {
        stack s = new stack();

        s.push(10);
        s.push(20);
        System.out.println("Top element :" + s.top());
        s.pop();
        s.push(30);
        s.pop();
        System.out.println("Top element :" + s.top());
    }
    static void Main()
    {
        Console.WriteLine("Enter the string : ");
        stack  s = new stack();
        string check;

        check = Console.ReadLine();
        int size = 0;

        foreach (char c in check)
        {
            s.push(c);
            size++;
        }
        foreach (char c in check)
        {
            // cout<<s.top()<<endl;
            if (c != s.top())
            {
                break;
            }
            s.pop();
            size--;
        }

        if (size > 0)
        {
            Console.WriteLine("This is not Palindrome");
        }
        else
        {
            Console.WriteLine("this is Palindrome");
        }
    }
Пример #6
0
        public void CanPopOffStack()
        {
            stack videogames = new stack();

            videogames.push(2);
            videogames.push(3);
            videogames.pop();

            Assert.Equal(2, videogames.Top.Value);
        }
Пример #7
0
            public void report()
            {
                bool todos   = false;
                bool exits   = false;
                int  pointer = roots;

                stacks.SP = 0;
                Console.WriteLine("tree--------");
                while (!exits)
                {
                    todos = false;
                    if (pointer > -1)
                    {
                        print(pointer);
                        if (nodes[pointer].sun > -1)
                        {
                            stacks.push(nodes[pointer].after);
                            pointer = nodes[pointer].sun;
                            todos   = true;
                        }
                        else
                        {
                            if (pointer > -1)
                            {
                                pointer = nodes[pointer].after;
                            }
                        }
                    }
                    if (pointer < 0 && stacks.SP < 1)
                    {
                        exits = true;
                    }
                    else
                    {
                        if (!todos && pointer < 0)
                        {
                            if (stacks.SP > 0)
                            {
                                pointer = stacks.pop();
                            }
                            else
                            {
                                pointer = -1;
                            }
                        }
                    }
                    if (pointer < 0 && stacks.SP < 1)
                    {
                        exits = true;
                    }
                }
            }
        /* Return true if expression has balanced Parenthesis */
        internal static bool areParenthesisBalanced(char[] exp)
        {
            /* Declare an empty character stack */
            stack st = new stack();

            /* check matching parenthesis */
            for (int i = 0; i < exp.Length; i++)
            {
                /*If the exp[i] is a starting
                 *  parenthesis then push it*/
                if (exp[i] == '{' || exp[i] == '(' || exp[i] == '[')
                {
                    st.push(exp[i]);
                }

                /* If exp[i] is an ending parenthesis
                 *  then pop from stack and check if the
                 *  popped parenthesis is a matching pair*/
                if (exp[i] == '}' || exp[i] == ')' || exp[i] == ']')
                {
                    /* If we see an ending parenthesis without
                     *  a pair then return false*/
                    if (st.Empty)
                    {
                        return(false);
                    }

                    /* Pop the top element from stack, if
                     *  it is not a pair parenthesis of character
                     *  then there is a mismatch. This happens for
                     *  expressions like {(}) */
                    else if (!isMatchingPair(st.pop(), exp[i]))
                    {
                        return(false);
                    }
                }
            }

            /* If there is something left in expression
             *  then there is a starting parenthesis without
             *  a closing parenthesis */

            if (st.Empty)
            {
                return(true); //balanced
            }
            else
            { //not balanced
                return(false);
            }
        }
Пример #9
0
 public void Main()
 {
     int n;
     stack s = new stack();
     Console.Write("Nhap n="); n = int.Parse(Console.ReadLine());
     while (n != 0)
     {
         s.push(n % 2);
         n = n / 2;
     }
     while (!s.empty())
         Console.Write(s.pop());
     Console.ReadKey();
 }
        public void NumToLinkedList(int number)
        {
            stack<int> st = new stack<int>();
            while (number != 0)
            {
                int reminder = number % 10;
                st.push(reminder);
                number =number/10;
            }

            while (st.length != 0)
            {
                lnk.Add(new node<int>(st.pop()));
            }
        }
        public void NumToString(int num)
        {
            string[] strDigit = {"zero" ,"one", "two", "Three", "Five", "Six", "Seven", "Eight", "Nine"};

            int digit;
            stack<string> stc = new stack<string>();

            while (num!=0)
            {
                digit = num % 10;
                num = num / 10;
                stc.push(strDigit[digit]);
            }

            while (! (stc.length == 0))
            {
                Console.Write("{0} ", stc.pop());
            }
        }
Пример #12
0
        static void Main(string[] args)
        {
            stack logs = new stack(1025);
            int   i    = 0;
            int   ii   = 0;

            logs.reported = true;
            for (i = 0; i < 20; i++)
            {
                logs.push(i);
            }
            logs.reported = false;
            logs.reporter();
            logs.dec();
            ii = logs.SP;
            for (i = 0; i < ii; i++)
            {
                Console.Write(" PoP:{0} ", logs.pop());
            }
            Console.WriteLine("");
        }
Пример #13
0
        public void PopExceptions()
        {
            stack broken = new stack();

            Assert.Throws <System.Exception>(() => broken.pop());
        }
Пример #14
0
 public virtual void delete_func_stack()
 {
     FuncAsyncStack.pop();
 }
Пример #15
0
 public void testDelete()
 {
     testList.pop();
 }