コード例 #1
0
        public void Push(int num)
        {
            StackElement temp = new StackElement();

            temp.num  = num;
            temp.next = this.head;
            this.head = temp;
        }
コード例 #2
0
        /// <summary>
        /// Push element on stack.
        /// </summary>
        /// <param name="value"></param>
        public void Push(T value)
        {
            StackElement <T> temp = new StackElement <T>();

            temp.Value = value;
            temp.Next  = this.head;
            this.head  = temp;
        }
コード例 #3
0
        /// <summary>
        /// Show element on stack and delete it from the stack.
        /// </summary>
        /// <returns></returns>
        public T Pop()
        {
            if (head == null)
            {
                throw new StackEmptyException();
            }
            T temp = this.head.Value;
            StackElement <T> pos = this.head;

            this.head = this.head.Next;
            return(temp);
        }
コード例 #4
0
        public int Pop()
        {
            if (head == null)
            {
                Console.WriteLine("Stack is empty!");
                return(0);
            }
            int          temp = this.head.num;
            StackElement pos  = this.head;

            this.head = this.head.next;
            return(temp);
        }
コード例 #5
0
 public Stack()
 {
     this.head = null;
 }