/** Custom implementation of the javaslist collection structure */public class my‑list {private node firstnode; // always points to the first element private node lastnode; // always point to the last element private int size; // set length // Add public Boolean add (node) {If (null = node) {Throw new illegalargumentexception ("Node element with null not allowed");} If (null = firstnode) {firstnode = node; // No element exists in the set, assign this element to the first element} else {node lastnode = getlast (); // two-way linked list lastnode. setnext (node); // point to the next element Surnode. setprev (lastnode); // point to the previous element} lastnode = node; // assign the newly added element to the last element size ++; // Add 1 return true for each length added;} // Add the public void addfirst (node) {If (node = NULL) element to the header of the List) {Throw new illegalargumentexception ("Do Not Allow null node elements");} If (firstnode = NULL) {lastnode = node;} else {node n = getfirst (); N. setprev (node); node. setnext (n) ;}firstnode = node; size ++ ;}// Add the public void addlast (node) {If (node = NULL) element at the end of the list) {Throw n EW illegalargumentexception ("Do Not Allow null node elements");} If (lastnode = NULL) {firstnode = node;} else {node n = getlast (); N. setnext (node); node. setprev (n) ;}lastnode = node; size ++ ;}// Delete the first public void removefirst () {node = firstnode in the list. getnext (); node. setprev (null); firstnode = node; size --;} // Delete the last element in the list public void removelast () {node = lastnode. getprev (); node. setnext (null); lastnode = node; size -- ;}// Delete the specified public v element in the list Oid remove (INT index) {If (index <0 | index> = size) {Throw new arrayindexoutofboundsexception ();} If (null = firstnode) {Throw new illegalstateexception ("no element in set");} int I = 0; node = firstnode; If (Index = 0) {node = node. getnext (); node. setprev (null); firstnode = node; size --; return;} If (Index = (size-1) {node = lastnode. getprev (); node. setnext (null); lastnode = node; size --; return;} If (index <size/2) {While (I! = Index) {node = node. getnext (); I ++ ;}} else {I = size-1; node = lastnode; while (I! = Index) {node = node. getprev (); I -- ;}} node next = node. getnext (); node Prev = node. getprev (); next. setprev (prev); Prev. setnext (next); size --;}/** return the elements at the specified position in this list (bipartite) */Public node get (INT index) {If (index <0 | index> = size) {Throw new arrayindexoutofboundsexception ();} If (null = firstnode) {Throw new illegalstateexception ("no element in set");} int I = 0; node; If (index <size/2) {node = firstnode; while (I! = Index) {node = node. getnext (); I ++ ;}} else {I = size-1; node = lastnode; while (I! = Index) {node = node. getprev (); I --;} return node;}/** return the element (common method) at the specified position in this list */Public node myget (INT index) {If (index <0 | index> = size) {Throw new arrayindexoutofboundsexception ();} If (null = firstnode) {Throw new illegalstateexception ("no element in set");} int I = 0; node = firstnode; while (I! = Index) {node = node. getnext (); I ++;} return node;}/** get the last element */Public node getlast () {If (null = firstnode) {Throw new illegalstateexception ("no element in set");} return lastnode;}/** get the last element */Public node getfirst () {If (null = firstnode) {Throw new illegalstateexception ("no element in set");} return firstnode;}/** get set length */Public int size () {return size ;}}