Java Reference
In-Depth Information
21.
O( n ).
22.
private Node getNodeAt( int givenPosition)
{
assert (firstNode != null ) && (1 <= givenPosition) && (givenPosition <= numberOfEntries);
Node currentNode = firstNode;
if (givenPosition == numberOfEntries)
currentNode = lastNode;
else if (givenPosition > 1) // traverse the chain to locate the desired node
{
for ( int counter = 1; counter < givenPosition; counter++)
currentNode = currentNode.getNextNode();
} // end if
assert currentNode != null ;
return currentNode;
} // end getNodeAt
Search WWH ::




Custom Search