예제 #1
0
 public DoubleNodeData <T> this[int index]
 {
     get
     {
         if (_size <= index || index < 0)
         {
             throw new IndexOutOfRangeException();
         }
         DoubleNodeData <T> result = begin;
         for (int i = 0; i < index; i += 1)
         {
             result = result.Next;
         }
         return(result);
     }
     set
     {
         if (_size <= index || index < 0)
         {
             throw new IndexOutOfRangeException();
         }
         DoubleNodeData <T> result = begin;
         for (int i = 0; i < index; i += 1)
         {
             result = result.Next;
         }
         result = value;
     }
 }
예제 #2
0
 public void Concat(DoubleLinkedList <T> nodeList)
 {
     this.end.Next       = nodeList.begin;
     nodeList.begin.Prev = this.end;
     this.end            = nodeList.end;
     _size += nodeList.Count;
 }
예제 #3
0
        public void ForEach(Action <DoubleNodeData <T> > action)
        {
            DoubleNodeData <T> node = begin;

            while (node != null)
            {
                action(node);
                node = node.Next;
            }
        }
예제 #4
0
 public DoubleNodeData<T> Add(T item)
 {
     DoubleNodeData<T> temp = new DoubleNodeData<T>(item);
     int index = save.CustomBinarySearch(temp, 0, save.Count, (x, y) => {
         if (comparer(x.data, y.data)) return -1;
         else return 1;
     });
     save.AddAfter(index, temp);
     return temp;
 }
예제 #5
0
 public void AddLast(DoubleNodeData <T> node)
 {
     end.Next  = node;
     node.Next = null;
     end       = node;
     if (_size == 0)
     {
         begin = node;
     }
     _size += 1;
 }
예제 #6
0
 public void AddFirst(DoubleNodeData <T> node)
 {
     node.Next = begin;
     node.Prev = null;
     begin     = node;
     if (_size == 0)
     {
         end = node;
     }
     _size += 1;
 }
예제 #7
0
        public override string ToString()
        {
            string             result = "";
            DoubleNodeData <T> pTemp  = begin;

            while (pTemp != null)
            {
                result += pTemp.ToString();
            }
            return(result);
        }
예제 #8
0
 public DoubleNodeData<T> this[int index]
 {
     get
     {
         if (this.Count <= index || index < 0) throw new IndexOutOfRangeException();
         DoubleNodeData<T> result = this.First;
         for (int i = 0; i < index; i += 1)
             result = result.Next;
         return result;
     }
 }
예제 #9
0
        public void AddBefore(int index, DoubleNodeData <T> node)
        {
            if (_size <= index || index < 0)
            {
                throw new IndexOutOfRangeException();
            }
            DoubleNodeData <T> indexNode = this[index];

            node.Next           = indexNode;
            node.Prev           = indexNode.Prev;
            indexNode.Prev.Next = node;
        }
예제 #10
0
        public DoubleNodeData <T> AddFirst(T value)
        {
            DoubleNodeData <T> node = new DoubleNodeData <T>(value);

            node.Next = begin;
            begin     = node;
            if (_size == 0)
            {
                end = node;
            }
            _size += 1;
            return(node);
        }
예제 #11
0
        public DoubleNodeData <T> AddLast(T value)
        {
            DoubleNodeData <T> node = new DoubleNodeData <T>(value);

            end.Next = node;
            end      = node;
            if (_size == 0)
            {
                begin = node;
            }
            _size += 1;
            return(node);
        }
예제 #12
0
 public bool MoveNext()
 {
     if (index >= 0)
     {
         currentItem = currentItem.Next;
     }
     index++;
     if (currentItem == null)
     {
         return(false);
     }
     return(true);
 }
예제 #13
0
        public DoubleNodeData <T> AddBefore(int index, T value)
        {
            if (_size <= index || index < 0)
            {
                throw new IndexOutOfRangeException();
            }
            DoubleNodeData <T> node      = new DoubleNodeData <T>(value);
            DoubleNodeData <T> indexNode = this[index];

            node.Next           = indexNode;
            node.Prev           = indexNode.Prev;
            indexNode.Prev.Next = node;
            return(node);
        }
예제 #14
0
        public DoubleNodeData <T> FindLast(T value)
        {
            DoubleNodeData <T> pTemp = end;

            while (pTemp != null)
            {
                if (pTemp.Prev.data.Equals(value))
                {
                    return(pTemp);
                }
                pTemp = pTemp.Prev;
            }
            return(null);
        }
예제 #15
0
        public DoubleNodeData <T> Find(T value)
        {
            DoubleNodeData <T> pTemp = begin;

            while (pTemp != null)
            {
                if (pTemp.data.Equals(value))
                {
                    return(pTemp);
                }
                pTemp = pTemp.Next;
            }
            return(null);
        }
예제 #16
0
        public DoubleLinkedList(IEnumerable <T> collection)
        {
            begin = new DoubleNodeData <T>(collection.ElementAt(0));
            DoubleNodeData <T> pNext = begin;
            DoubleNodeData <T> pPrev = null;
            int count = collection.Count();

            for (int i = 1; i < count; i++)
            {
                DoubleNodeData <T> next = new DoubleNodeData <T>(collection.ElementAt(i));
                pNext.Next = next;
                pNext.Prev = pPrev;
                pPrev      = pNext;
                pNext      = next;
            }
            end   = pNext;
            _size = count;
        }
예제 #17
0
 public PriorityDoubleLinkedList(Func<T, T, bool> comparer, IEnumerable<T> collection)
 {
     this.comparer = comparer;
     save = new DoubleLinkedList<T>();
     foreach(T item in collection)
     {
         if (save.Count == 0) save.AddFirst(item);
         else
         {
             DoubleNodeData<T> temp = new DoubleNodeData<T>(item);
             int index = save.CustomBinarySearch(temp, 0, save.Count, (x, y) => {
                 if (comparer(x.data, y.data)) return -1;
                 else return 1;
             });
             save.AddAfter(index, temp);
         }
     }
 }
예제 #18
0
 public void Remove(int index)
 {
     if (index >= 0 && index < _size)
     {
         DoubleNodeData <T> removeNode = this[index];
         DoubleNodeData <T> prevNode   = removeNode.Prev;
         DoubleNodeData <T> nextNode   = removeNode.Next;
         if (prevNode != null)
         {
             prevNode.Next = nextNode;
         }
         if (nextNode != null)
         {
             nextNode.Prev = prevNode;
         }
         _size--;
     }
 }
예제 #19
0
        public void RemoveLast(T value)
        {
            DoubleNodeData <T> temp = end;

            while (temp != null)
            {
                if (temp.data.Equals(value))
                {
                    DoubleNodeData <T> prevNode = temp.Prev;
                    DoubleNodeData <T> nextNode = temp.Next;
                    if (prevNode != null)
                    {
                        prevNode.Next = nextNode;
                    }
                    if (nextNode != null)
                    {
                        nextNode.Prev = prevNode;
                    }
                    --_size;
                    break;
                }
                temp--;
            }
        }
예제 #20
0
 public DoubleLinkedList()
 {
     begin = end = null;
     _size = 0;
 }
예제 #21
0
 public void Reset()
 {
     currentItem = null;
 }
예제 #22
0
 public bool MoveNext()
 {
     currentItem = currentItem.Next;
     if (currentItem == null) return false;
     return true;
 }
예제 #23
0
 public PriorityDoubleLinkedListIEnumerator(PriorityDoubleLinkedList<T> list)
 {
     this.list = list;
     currentItem = null;
     index = -1;
 }
예제 #24
0
 public DoubleLinkedListEnumerator(DoubleLinkedList <T> list)
 {
     this.list   = list;
     currentItem = null;
     index       = -1;
 }