public void delete(LLNode location, int value, LLNode previous = null) { if (location.Value == value) { LLNode temp; if (location == root) { temp = root; root = location.Next; linkedList.Remove(temp); } else { temp = location; previous.Next = location.Next; linkedList.Remove(temp); } } else { if (location.Next != null) { delete(location.Next, value, location); } } }
public void removeNth(LLNode currentLocation, int value, LLNode previous = null) { if (value == 0) { delete(currentLocation, currentLocation.Value, previous); } if (currentLocation.Next != null) { value--; removeNth(currentLocation.Next, value, currentLocation); } }
public void insert(LLNode location, int value) { if(location.Next == null) { LLNode newNode = new LLNode(value); linkedList.Add(newNode); location.Next = linkedList[linkedList.IndexOf(newNode)]; } else { insert(location.Next, value); } }
public int findNth(LLNode currentLocation, int value) { if (value == 0) { Console.WriteLine("the requested node has value " + currentLocation.Value); return currentLocation.Value; } if(currentLocation.Next != null) { value--; return findNth(currentLocation.Next, value); } return -1337; }
public void printList(LLNode location) { Console.Write(location.Value.ToString() + ", "); if (location.Next != null) { printList(location.Next); } }
public LinkedList(int root) { this.root = new LLNode(root); linkedList = new List<LLNode>(); linkedList.Add(this.root); }