Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RakhmedovRS/ca3d76ae29d1210d6eb312f9350385d5 to your computer and use it in GitHub Desktop.
Save RakhmedovRS/ca3d76ae29d1210d6eb312f9350385d5 to your computer and use it in GitHub Desktop.
/**
* Get the value of the index-th node in the linked list. If the index is invalid, return -1.
*/
public int get(int index)
{
if (index < 0 || index >= size)
{
return -1;
}
Link current = head;
while (index-- >= 0)
{
current = current.next;
}
return current.value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment