public LinkedList(LinkedList <Type> listToCopy) // Copy { LinkedListNode <Type> thisWorkingNode, thatWorkingNode = listToCopy.GetHead(); head = null; tail = null; if (thatWorkingNode != null) { head = new LinkedListNode <Type>(thatWorkingNode); thisWorkingNode = head; thatWorkingNode = thatWorkingNode.GetNext(); while (thatWorkingNode != null) { thisWorkingNode.SetNext(new LinkedListNode <Type>(thatWorkingNode)); tail = thisWorkingNode.GetNext(); tail.SetPrev(thisWorkingNode.GetPrev()); thisWorkingNode = thisWorkingNode.GetNext(); thatWorkingNode = thatWorkingNode.GetNext(); tail = thatWorkingNode; } } }
private void UpdateTail(LinkedListNode <Type> inNode) { LinkedListNode <Type> workingNode = inNode; while (workingNode.GetNext() != null) { workingNode = workingNode.GetNext(); } tail = workingNode; }
public Type Remove(Type target) { LinkedListNode <Type> workingNode, nodeToRemove = SearchList(target); workingNode = nodeToRemove.GetPrev(); workingNode.SetNext(nodeToRemove.GetNext()); workingNode = workingNode.GetNext(); workingNode.SetPrev(nodeToRemove.GetPrev()); UpdateTail(workingNode); return(nodeToRemove.GetData()); }
public void DisplayList() { LinkedListNode <Type> workingNode = head; Console.WriteLine("<List Name>:"); while (workingNode != null) { Console.WriteLine(workingNode.ToString()); workingNode = workingNode.GetNext(); } Console.WriteLine("Head: " + head); Console.WriteLine("Tail: " + tail); }
private LinkedListNode <Type> SearchList(Type target) { LinkedListNode <Type> workingNode; if (head.Equals(target)) { return(head); } else { workingNode = head.GetNext(); while (!workingNode.Equals(target)) { workingNode = workingNode.GetNext(); } return(workingNode); } }