public T Remove(int index) { var current = head; T removed; if (index < 0 || index >= count) { throw new IndexOutOfRangeException("That index is not in the list"); } else if (index == 0) { removed = head.Data; head = head.next; } else if (index == (count - 1)) { removed = tail.Data; for (int i = 0; i < count; i++) { if (i == index - 1) { break; } else { current = current.next; } } tail = current; current.next = null; } else if (count == 1) { removed = head.Data; head = null; tail = null; } else { for (int i = 0; i < count; i++) { if (i == index - 1) { break; } else { current = current.next; } } removed = current.next.Data; current.next = current.next.next; } count--; return(removed); }
public void Add(T data) { CustomLinkedNode <T> newNode = new CustomLinkedNode <T>() { Data = data }; if (head == null) { head = newNode; current = newNode; tail = newNode; count = 1; } else { tail.next = newNode; tail = newNode; count++; } }
public string GetData(int index) { string returnValue = null; CustomLinkedNode current = Head; if ((index < 0) || (index >= Count)) { throw new IndexOutOfRangeException(); } else { for (int i = 0; i < index; i++) { current = current.Next; } returnValue = current.Data; } return(returnValue); }
public void Add(string inputData) { if (Head == null) { Head = new CustomLinkedNode(inputData); Count++; } else { CustomLinkedNode current = Head; while (current.Next != null) { current = current.Next; } current.Next = new CustomLinkedNode(inputData); Count++; } }
public T GetData(int index) { var current = head; if (index < 0 || index >= count) { throw new IndexOutOfRangeException("That index is not in the list"); } else { for (int i = 0; i < count; i++) { if (i == index) { break; } else { current = current.next; } } return(current.Data); } }
public CustomLinkedNode(string inputData) { this.Data = inputData; this.Next = null; }