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; } }
public void Concat(DoubleLinkedList <T> nodeList) { this.end.Next = nodeList.begin; nodeList.begin.Prev = this.end; this.end = nodeList.end; _size += nodeList.Count; }
public void ForEach(Action <DoubleNodeData <T> > action) { DoubleNodeData <T> node = begin; while (node != null) { action(node); node = node.Next; } }
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; }
public void AddLast(DoubleNodeData <T> node) { end.Next = node; node.Next = null; end = node; if (_size == 0) { begin = node; } _size += 1; }
public void AddFirst(DoubleNodeData <T> node) { node.Next = begin; node.Prev = null; begin = node; if (_size == 0) { end = node; } _size += 1; }
public override string ToString() { string result = ""; DoubleNodeData <T> pTemp = begin; while (pTemp != null) { result += pTemp.ToString(); } return(result); }
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; } }
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; }
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); }
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); }
public bool MoveNext() { if (index >= 0) { currentItem = currentItem.Next; } index++; if (currentItem == null) { return(false); } return(true); }
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); }
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); }
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); }
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; }
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); } } }
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--; } }
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--; } }
public DoubleLinkedList() { begin = end = null; _size = 0; }
public void Reset() { currentItem = null; }
public bool MoveNext() { currentItem = currentItem.Next; if (currentItem == null) return false; return true; }
public PriorityDoubleLinkedListIEnumerator(PriorityDoubleLinkedList<T> list) { this.list = list; currentItem = null; index = -1; }
public DoubleLinkedListEnumerator(DoubleLinkedList <T> list) { this.list = list; currentItem = null; index = -1; }