Beispiel #1
0
        IEnumerator <T> IEnumerable <T> .GetEnumerator()
        {
            DoublyNode <T> current = head;

            while (current != null)
            {
                yield return(current.Data);

                current = current.Next;
            }
        }
Beispiel #2
0
        public bool Contains(T data)
        {
            DoublyNode <T> current = head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    return(true);
                }
                current = current.Next;
            }
            return(false);
        }
Beispiel #3
0
        int count;                           // количество элементов в списке

        // добавление элемента
        public void AddLast(T data)
        {
            DoublyNode <T> node = new DoublyNode <T>(data);

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }
            tail = node;
            count++;
        }
Beispiel #4
0
        public void AddFirst(T data)
        {
            DoublyNode <T> node = new DoublyNode <T>(data);
            DoublyNode <T> temp = head;

            node.Next = temp;
            head      = node;
            if (count == 0)
            {
                tail = head;
            }
            else
            {
                temp.Previous = node;
            }
            count++;
        }
Beispiel #5
0
        public T RemoveLast()
        {
            if (count == 0)
            {
                throw new InvalidOperationException();
            }
            T output = tail.Data;

            if (count == 1)
            {
                head = tail = null;
            }
            else
            {
                tail      = tail.Previous;
                tail.Next = null;
            }
            count--;
            return(output);
        }
Beispiel #6
0
        public T RemoveFirst()
        {
            if (count == 0)
            {
                throw new InvalidOperationException();
            }
            T output = head.Data;

            if (count == 1)
            {
                head = tail = null;
            }
            else
            {
                head          = head.Next;
                head.Previous = null;
            }
            count--;
            return(output);
        }
Beispiel #7
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }