Created
June 27, 2022 00:27
-
-
Save RakhmedovRS/ca3d76ae29d1210d6eb312f9350385d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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