public void Insert(int index, T t) { if (IsEmpty && index > 0) { throw new IndexOutOfRangeException(); } if (index >= Count) { throw new IndexOutOfRangeException(); } if (index < 0) { throw new IndexOutOfRangeException(); } if (index == 0) { AddFirst(t); return; } SingleDirectionNode <T> node = new Basic.SingleDirectionNode <T>(t); SingleDirectionNode <T> preNode = this[index]; SingleDirectionNode <T> nextNode = this[index + 1]; node.Next = nextNode; preNode.Next = node; size += 1; }
public void AddFirst(T t) { SingleDirectionNode <T> node = new Basic.SingleDirectionNode <T>(t); node.Next = head; head = node; size += 1; }
public void AddLast(T t) { SingleDirectionNode <T> node = new Basic.SingleDirectionNode <T>(t); if (tail == null) { tail = this[size - 1]; } tail.Next = node; size += 1; }