I’m learning about linked lists right now. I found an example for java that plac

I’m learning about linked lists right now. I found an example for java that places a new node into the 3rd position on a linked list, but I’ve only ever seen insertion into a certain spot in the middle of a list like this done using 2 additional nodes, current and previous. I’ve never seen anything like .getNext after another one like this. So I need someone to explain what each part of this snippet of code does and please rewrite this code using nodes current and previous so I can understand how it relates and compares.  Elem is the name given to the node being inserted and you don’t have to instantiate current and previous in the rewrite. I can just assume it’s already done. Please let me know if more information is needed to answer! elem.setNext( first.getNext().getNext());  first.getNext().setNext(elem);  numberOfElems++;
Requirements:

Leave a comment

Your email address will not be published. Required fields are marked *