Guest User

Untitled

a guest
Jul 15th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. private Node getNode(int n) // Returns the 'n'th Node in the List
  2. {
  3. Node temp = null;
  4.  
  5. if (n <= getSize()/2) // determine if we should start searching from the head
  6. {
  7. temp = getHeadNode();
  8.  
  9. for (int i = 0; i < n; ++i, temp = temp.getNextNode());
  10. }
  11. else // or the tail
  12. {
  13. temp = getTailNode();
  14.  
  15. for (int i = getSize()-1; i > n; --i, temp = temp.getPreviousNode());
  16. }
  17.  
  18. if (temp == null)
  19. System.out.println("Warning, returning null for index " + n);
  20.  
  21. return temp;
  22. }
Add Comment
Please, Sign In to add comment