Exemple #1
0
        public int Pop(DLLStack stack)
        {
            if (stack.count == 0)
            {
                return(-1);
            }

            DLLNode head = stack.head;

            int item = head.data;

            stack.head = head.next;

            if (stack.head != null)
            {
                stack.head.prev = null;
            }

            stack.count--;

            if (stack.count % 2 != 0)
            {
                stack.mid = stack.mid.next;
            }

            return(item);
        }
Exemple #2
0
        public int FindMiddle(DLLStack stack)
        {
            if (stack.count == 0)
            {
                return(-1);
            }

            return(stack.mid.data);
        }
Exemple #3
0
        public void Push(DLLStack stack, int data)
        {
            DLLNode newNode = new DLLNode(data);

            newNode.prev = null;
            newNode.next = stack.head;

            stack.count++;

            if (stack.count == 1)
            {
                stack.mid = newNode;
            }
            else
            {
                stack.head.prev = newNode;

                if (stack.count % 2 != 0)
                {
                    stack.mid = stack.mid.prev;
                }
            }
        }
Exemple #4
0
        public DLLStack CreateStack()
        {
            var myStack = new DLLStack();

            return(myStack);
        }