1: // Returns a reference to the node at a given position.
2: // Precondition: The chain is not empty;
3: // 1 <= givenPosition <= numberOfEntries.
4: private Node getNodeAt(int givenPosition)
5: {
6: assert !isEmpty() && (1 <= givenPosition) && (givenPosition <= numberOfEntries);
7: Node currentNode = firstNode;
8: // Traverse the chain to locate the desired node
9: // (skipped if givenPosition is 1)
10: for (int counter = 1; counter < givenPosition; counter++)
11: currentNode = currentNode.getNextNode();
12: assert currentNode != null;
13: return currentNode;
14: } // end getNodeAt
15: // Version 4.0