Beispiel #1
0
        public T Pop()
        {
            if (this.Count == 0)
            {
                throw  new InvalidOperationException();
            }

            T current = this.top.Value;

            this.top = this.top.Next;

            this.Count--;

            return(current);
        }
        public void Push(T value)
        {
            if (this.Count == 0)
            {
                this.lastPushed = new StackNode <T>(value);
            }
            else
            {
                var newLast = new StackNode <T>(value);
                newLast.PrevNode = this.lastPushed;
                this.lastPushed  = newLast;
            }

            this.Count++;
        }
        public T[] ToArray()
        {
            T[] array = new T[this.Count];

            StackNode current = this.top;

            int index = 0;

            while (current != null)
            {
                array[index++] = current.Value;
                current        = current.Next;
            }

            return(array);
        }
Beispiel #4
0
        public T[] ToArray()
        {
            T[] arr = new T[this.Count];

            StackNode stackNode = this.top;

            int index = 0;

            while (stackNode != null)
            {
                arr[index++] = stackNode.Value;
                stackNode    = stackNode.Next;
            }

            return(arr);
        }
 public StackNode(T value, StackNode next)
 {
     this.Value = value;
     this.Next  = next;
 }
        public void Push(T element)
        {
            this.top = new StackNode(element, this.top);

            this.Count++;
        }
Beispiel #7
0
        public void Push(T item)
        {
            this.top = new StackNode(item, this.top);

            this.Count++;
        }
Beispiel #8
0
 public void Clear()
 {
     this.top = null;
     Count    = 0;
 }