Esempio n. 1
0
 /// <summary>
 /// Добавление элемента в конец стека
 /// </summary>
 public void Push(T element)
 {
     if (top == null)
     {
         top = new DoublyNode <T>(element);
         Length++;
     }
     else
     {
         top.Next      = new DoublyNode <T>(element);
         top.Next.Prev = top;
         top           = top.Next;
         Length++;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Добавление элемента в конец очереди
 /// </summary>
 public void Enqueue(T element)
 {
     if (head == null)
     {
         DoublyNode <T> _current = new DoublyNode <T>(element);
         tail = _current;
         head = _current;
         Length++;
     }
     else
     {
         DoublyNode <T> newNode = new DoublyNode <T>(element);
         tail.Next    = newNode;
         newNode.Prev = tail;
         tail         = newNode;
         Length++;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Изъятие первого элемента
        /// </summary>
        public DoublyNode <T> Dequeue()
        {
            var ans = head;

            if (head == null)
            {
                return(null);
            }
            head = head.Next;
            if (head != null)
            {
                head.Prev = null;
            }
            else
            {
                tail = null;
            }

            Length--;
            return(ans);
        }
Esempio n. 4
0
        /// <summary>
        /// Изъятие элемента из конца стека
        /// </summary>
        public DoublyNode <T> Pop()
        {
            var ans = top;

            if (top == null)
            {
                return(null);
            }

            top = top.Prev;

            if (top != null)
            {
                top.Next = null;
            }
            else
            {
                top = null;
            }

            Length--;
            return(ans);
        }
Esempio n. 5
0
 public Stack()
 {
     top    = null;
     Length = 0;
 }
Esempio n. 6
0
 public DoublyNode(T data)
 {
     Data = data;
     Next = null;
     Prev = null;
 }
Esempio n. 7
0
 public Queue()
 {
     tail   = head = null;
     Length = 0;
 }