private Node FindNodeByData(Node currentlySearchingNode, string data) { if (currentlySearchingNode.GetName() == data) { return currentlySearchingNode; } else if (currentlySearchingNode.GetNextNode() != null) { return FindNodeByData(currentlySearchingNode.GetNextNode(), data); } return null; // Recusion here is not ideal, due to the fact that, for a sufficiently large queue, this recursive loop will blow the stack }
public void ShouldBeAbleToGetAndSetNextNode() { Node nodeOne = new Node(); Node target = new Node(nodeOne); Node expected = nodeOne; Node actual = target.GetNextNode(); Assert.AreEqual(expected, actual); Node newNode = new Node("Emily"); target.SetNextNode(newNode); expected = newNode; actual = target.GetNextNode(); Assert.AreEqual(expected, actual); }
public void Enqueue(Node newNode) { newNode.SetNextNode(tailNode); tailNode = newNode; if (tailNode.GetNextNode() == null) { headNode = tailNode; } }
public void EnqueueShouldAddPreviousTailToNewTailsNextNode() { LinkedListQueue target = new LinkedListQueue(); Node nodeOne = new Node(); Node nodeTwo = new Node(); target.Enqueue(nodeOne); target.Enqueue(nodeTwo); Node expected = nodeOne; Node actual = nodeTwo.GetNextNode(); Assert.AreEqual(expected, actual); }