Exemple #1
0
        public T Pop()
        {
            if (top == null)
            {
                throw new OverflowException();
            }

            var item = top.Value;

            top = top.Next;
            size--;

            return(item);
        }
Exemple #2
0
        public void Enqueue(T item)
        {
            var node = new SingleLinkNode <T>(item);

            if (tail == null)
            {
                head = tail = node;
            }
            else
            {
                tail.Next = node;
                tail      = tail.Next;
            }
            size++;
        }
Exemple #3
0
        public T Dequeue()
        {
            if (head == null)
            {
                throw new OverflowException();
            }

            T item = head.Value;

            head = head.Next;
            if (head == null)
            {
                tail = null;
            }
            size--;

            return(item);
        }
Exemple #4
0
 public LinkedStack()
 {
     top  = null;
     size = 0;
 }
Exemple #5
0
 public void Push(T item)
 {
     top = new SingleLinkNode <T>(item, top);
     size++;
 }
Exemple #6
0
 public SingleLinkNode()
 {
     value = default(T);
     next  = null;
 }
Exemple #7
0
 public SingleLinkNode(T value, SingleLinkNode <T> next)
 {
     this.value = value;
     this.next  = next;
 }
Exemple #8
0
 public SingleLinkNode(T value)
 {
     this.value = value;
     next       = null;
 }
Exemple #9
0
 public LinkedQueue()
 {
     head = null;
     tail = null;
     size = 0;
 }