On page 69 of this book, there is a method called getElement that assists with inserting values into a linked list.
The code is as follows:
Code:
1. private Element getElement(int index) {
2. Element element = _headAndTail.getNext();
3.
4. for (int i = index; i > 0; --i) {
5. element = element.getNext();
6. }
7.
8. return element;
9. }
Could someone please explain in detail what each line of code is doing, particularly lines 2, 4 and 5?
New programmer here, any help will be gratefully appreciated.