Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Node getNode(int n) // Returns the 'n'th Node in the List
- {
- Node temp = null;
- if (n <= getSize()/2) // determine if we should start searching from the head
- {
- temp = getHeadNode();
- for (int i = 0; i < n; ++i, temp = temp.getNextNode());
- }
- else // or the tail
- {
- temp = getTailNode();
- for (int i = getSize()-1; i > n; --i, temp = temp.getPreviousNode());
- }
- if (temp == null)
- System.out.println("Warning, returning null for index " + n);
- return temp;
- }
Add Comment
Please, Sign In to add comment