public void Insert(int index, T item) { if (item == null) { throw new ArgumentNullException(); } if (index < StartIndex || index >= Count + StartIndex) { throw new IndexOutOfRangeException(); } int i = StartIndex; if (index == StartIndex) { IndexArrayElement <T> Element = new IndexArrayElement <T>(head.Value); Element.Next = head.Next; head.Value = item; Count++; } IndexArrayElement <T> temp = head; while (i != index) { temp = temp.Next; i++; } IndexArrayElement <T> newElement = new IndexArrayElement <T>(item); newElement.Next = temp.Next; temp.Next = newElement; Count++; }
public T this[int index] { get { if (index < StartIndex || index >= Count + StartIndex) { throw new IndexOutOfRangeException(); } int i = StartIndex; IndexArrayElement <T> temp = head; while (i != index) { temp = temp.Next; i++; } return(temp.Value); } set { if (index < StartIndex || index >= Count + StartIndex) { throw new IndexOutOfRangeException(); } int i = StartIndex; IndexArrayElement <T> temp = head; while (i != index) { temp = temp.Next; i++; } temp.Value = value; } }
public void RemoveAt(int index) { if (index < StartIndex || index >= Count + StartIndex) { throw new IndexOutOfRangeException(); } int i = StartIndex; if (i == index) { head = head.Next; Count--; return; } IndexArrayElement <T> temp = head; while (i != index - 1) { temp = temp.Next; i++; } temp.Next = temp.Next.Next; Count--; }
public bool Remove(T item) { if (item == null) { throw new ArgumentNullException(); } IndexArrayElement <T> temp = head; if (head.Value.Equals(item)) { head = head.Next; Count--; return(true); } while (temp.Next != null && !temp.Next.Value.Equals(item)) { temp = temp.Next; } if (temp.Next != null) { temp.Next = temp.Next.Next; Count--; return(true); } return(false); }
public IndexArray(int start, T[] array) { StartIndex = start; head = null; for (int i = 0; i < array.Length; i++) { Add(array[i]); } }
public void Clear() { if (head == null) { return; } else { while (head != null) { head = head.Next; Count--; } } }
public void Add(T item) { if (head == null) { head = new IndexArrayElement <T>(item); } else { IndexArrayElement <T> temp = head; while (temp.Next != null) { temp = temp.Next; } temp.Next = new IndexArrayElement <T>(item); } Count++; }
public bool Contains(T item) { if (item == null) { throw new ArgumentNullException(); } IndexArrayElement <T> temp = head; while (temp != null) { if (temp.Value.Equals(item)) { return(true); } temp = temp.Next; } return(false); }
public int IndexOf(T item) { if (item == null) { throw new ArgumentNullException(); } int index = StartIndex; IndexArrayElement <T> temp = head; while (temp != null) { if (temp.Value.Equals(item)) { return(index); } temp = temp.Next; index++; } return(-1); }
public void CopyTo(T[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException("The array cannot be null."); } if (arrayIndex < 0) { throw new ArgumentOutOfRangeException("The starting array index cannot be negative."); } if (Count > array.Length - arrayIndex + 1) { throw new ArgumentException("The destination array has fewer elements than the collection."); } IndexArrayElement <T> temp = head; int i = 0; while (temp != null) { array[i + arrayIndex] = temp.Value; temp = temp.Next; } }
public IndexArrayElement(T value) { this.Value = value; Next = null; }
public IndexArrayElement() { Value = default(T); Next = null; }
public IndexArray(int start) { StartIndex = start; head = null; }
public IndexArray() { head = null; StartIndex = 0; }