public void Remove(int index) { var nodeToRemove = this[index]; if (this.Count == 1) { this.head = null; this.tail = null; } else { var nextNode = nodeToRemove.Next; ISimpleLinkedListNode <T> prevNode = null; try { prevNode = this[index - 1]; } catch (IndexOutOfRangeException) { } if (prevNode == null) { this.head = nextNode; } else { prevNode.Next = nextNode; } } this.Count--; }
public ISimpleLinkedListNode <T> Add(T element) { var newNode = new SimpleLinkedListNode <T>(element); if (this.Count == 0) { this.head = newNode; this.tail = newNode; } else { this.tail.Next = newNode; this.tail = newNode; } this.Count++; return(newNode); }
public SimpleLinkedList() { this.Count = 0; this.head = null; this.tail = null; }