public void Push(T item) { firstValue = new LinkedValue <T>() { current = item, next = firstValue }; _elements++; if (lastValue == null) { lastValue = firstValue; } if (firstValue.next != null) { firstValue.next.previous = firstValue; } if (_elements > Size && Size > 0) { if (_throwWhenFull) { throw new LinkedListException("The linked list has reached the limit of " + Size + " items."); } _elements = Size; LinkedValue <T> value = lastValue; lastValue = value.previous; lastValue.next = null; value.previous = null; value.next = null; } }
public void CopyTo(T[] array, int arrayIndex) { LinkedValue <T> val = firstValue; while (val != null) { array[arrayIndex++] = val.current; val = val.next; } }
public T[] GetAsReverseArray() { T[] array = new T[_elements]; int i = 0; LinkedValue <T> val = lastValue; while (val != null) { array[i++] = val.current; val = val.previous; } return(array); }
public T[] GetAsArray() { T[] array = new T[_elements]; int i = 0; LinkedValue <T> val = firstValue; while (val != null) { array[i++] = val.current; val = val.next; } return(array); }
public bool Contains(T item) { LinkedValue <T> val = firstValue; while (val != null) { if (val.current.Equals(item)) { return(true); } val = val.next; } return(false); }
public bool MoveNext() { if (this.now == null) { this.now = list.firstValue; if (this.now == null) { return(false); } return(true); } if (this.now.next == null) { return(false); } this.now = this.now.next; return(true); }
public bool Remove(T item) { LinkedValue <T> val = firstValue; while (val != null) { if (val.current.Equals(item)) { val.previous.next = val.next; val.next.previous = val.previous; val.next = null; val.previous = null; return(true); } val = val.next; } return(false); }
public T Pop() { if (firstValue == null) { throw new LinkedListException("The linked list is empty."); } _elements--; LinkedValue <T> value = firstValue; if (value.next != null) { firstValue = value.next; firstValue.previous = null; } else { firstValue = null; lastValue = null; } return(value.current); }
public T Dequeue() { if (lastValue == null) { throw new LinkedListException("The linked list is empty."); } _elements--; LinkedValue <T> value = lastValue; if (value.previous != null) { lastValue = value.previous; lastValue.next = null; } else { firstValue = null; lastValue = null; } return(value.current); }
void IDisposable.Dispose() { list = null; now = null; }
public void Reset() { this.now = null; }
public LinkedListEnumerator(LinkedList <T> list) { this.list = list; this.now = null; }
public void Clear() { firstValue = null; lastValue = null; _elements = 0; }