Esempio n. 1
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);
        }
Esempio n. 2
0
        public void Push(T data)
        {
            DoublyNode <T> node = new DoublyNode <T>(data);

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }
            tail = node;
            count++;
        }
Esempio n. 3
0
        public void AddFront(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++;
        }
Esempio n. 4
0
        public T Pop()
        {
            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);
        }
Esempio n. 5
0
        public T Dequeue()
        {
            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);
        }
Esempio n. 6
0
 public bool MoveNext()
 {
     if (head == null)
     {
         return(false);
     }
     if (node == null)
     {
         node = head;
         return(true);
     }
     if (node.Next != null)
     {
         node = node.Next;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 7
0
        public bool Remove(T data)
        {
            DoublyNode <T> current = head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    break;
                }
                current = current.Next;
            }

            if (current != null)
            {
                if (current.Next != null)
                {
                    current.Next.Previous = current.Previous;
                }
                else
                {
                    tail = current.Previous;
                }

                if (current.Previous != null)
                {
                    current.Previous.Next = current.Next;
                }
                else
                {
                    head = current.Next;
                }

                count--;
                return(true);
            }
            return(false);
        }
Esempio n. 8
0
 public void Reset()
 {
     node = head;
 }
Esempio n. 9
0
 public DoublyEnumerator(DoublyNode <T> h)
 {
     head = h;
 }
Esempio n. 10
0
 private void MoveDown(DoublyNode <int> el)
 {
     linkedList.RemoveBack();
     linkedList.AddFront(el.Data);
 }
Esempio n. 11
0
 private void MoveUp(DoublyNode <int> el)
 {
     linkedList.RemoveFront();
     linkedList.Add(el.Data);
 }
Esempio n. 12
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }