Element insertion and removal

A linked list is a sequence of nodes with efficient
// element insertion and removal.// This class contains a subset of the methods of the// standard java.util.LinkedList class. //nested class to represent a node //only instance variable that points to the first node. // Returns the first element in the linked list.// Removes the first element in the linked list.
change the reference since it's removed. element to the front of the linked list.
an iterator for iterating through this list.//just change pointers, and create identical one//then set it to pointer.next//nested class to define its iterator// Constructs an iterator that points to the front
// of the linked list. // Tests if there is an element after the iterator position.// // Adds an element before the iterator position // and moves the iterator past the inserted element. // Removes the last traversed element. This method may // only be called after a call to the next() method.// //stepping back //this also means that remove() cannot be called twice in a row.
The ListIterator interface allows access of a position in a linked list.
// This interface contains a subset of the methods of the
// standard java.util.ListIterator interface. The methods for
// backward traversal are not included.
Moves the iterator past the next element.if there is an element after the iterator position.Adds an element before the iterator position // and moves the iterator past the inserted element. Removes the // Sets the last traversed element to a different value. last traversed element. This method may // only be called after a call to the next() method.
Powered by