예제 #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);
        }
예제 #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++;
        }
예제 #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++;
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
     }
 }
예제 #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);
        }
예제 #8
0
 public void Reset()
 {
     node = head;
 }
예제 #9
0
 public DoublyEnumerator(DoublyNode <T> h)
 {
     head = h;
 }
예제 #10
0
 private void MoveDown(DoublyNode <int> el)
 {
     linkedList.RemoveBack();
     linkedList.AddFront(el.Data);
 }
예제 #11
0
 private void MoveUp(DoublyNode <int> el)
 {
     linkedList.RemoveFront();
     linkedList.Add(el.Data);
 }
예제 #12
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }