Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Get a linked list node by index (0-indexed) */
- public Data get(int index) {
- if (index < 0 || index >= size) { // 1
- throw new IndexOutOfBoundsException("Invalid linked list node."); // 1
- }
- Node<Data> current = head; // 2
- int i = 0; // 3
- while (i < index) { // 4
- current = current.next; // 4
- i++; // 4
- }
- return current.data; // 5
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement