示例#1
0
 // 인덱스 위치에 삽입
 public void Insert(T _data, int index)
 {
     ++Length;
     if (null == tail)
     {
         tail = new DCLNode <T>(_data);
         return;
     }
     Find(index).InsertNext(new DCLNode <T>(_data));
 }
示例#2
0
 // 리스트 마지막에 노드 삽입
 public void Add(T _data)
 {
     ++Length;
     if (null == tail)
     {
         tail = new DCLNode <T>(_data);
         return;
     }
     tail = tail.InsertNext(new DCLNode <T>(_data));
 }
示例#3
0
 // 노드 뒤에 삽입
 public DCLNode <T> InsertNext(DCLNode <T> node)
 {
     if (null != node)
     {
         node.prev = this;
         node.next = next;
         next.prev = node;
         next      = node;
     }
     return(node);
 }
示例#4
0
        IEnumerator IEnumerable.GetEnumerator()
        {
            if (current == null)
            {
                current = front;
            }
            do
            {
                yield return(current.data);

                current = current.next;
            } while (current != front);
        }
示例#5
0
        // 노드 출력
        public void Display()
        {
            if (null == tail)
            {
                Console.WriteLine("리스트가 비어있습니다!");
                return;
            }
            DCLNode <T> n = tail.next;

            for (int i = 0; i < Length; ++i, n = n.next)
            {
                Console.Write(i + "번지 원소 : ");
                n.Display();
                Console.WriteLine();
            }
            Console.WriteLine("Tail : " + tail.data);
        }
示例#6
0
        // 해당 인덱스 노드 찾기
        public DCLNode <T> Find(int index)
        {
            // 인덱스 범위 벗어날 경우
            if (0 > index || index >= Length)
            {
                Console.WriteLine("해당 번지의 노드는 존재하지 않습니다");
                return(null);
            }

            // 해당 인덱스 노드 탐색
            DCLNode <T> node = tail.next;

            while (0 != index)
            {
                --index;
                node = node.next;
            }
            return(node);
        }
示例#7
0
        // 노드 삭제
        public void Remove(DCLNode <T> n)
        {
            if (isEmpty)
            {
                Console.WriteLine("삭제할 노드가 없습니다");
                return;
            }

            --Length;
            // 삭제할 노드가 tail인 경우
            if (n == tail)
            {
                tail = tail.Remove().prev;
                return;
            }
            for (DCLNode <T> node = tail.next; node != tail; node = node.next)
            {
                if (n == node)
                {
                    node.Remove();
                    return;
                }
            }
        }
示例#8
0
 public void Reset()
 {
     current = tail;
 }