Iterative:

public void appendIter(int dx) { Node nxp = new Node (dx); //list is empty if(head == null) { head = nxp; return; } //list not empty while(nxp.getNext()!= null) { nxp.getNext(); } nxp.setNext(nxp); }

and Recursive:

public void appendRec1(int dx) { head = appendRec2(head, dx); } public Node appendRec2(Node hp, int dx) { Node nxp; if(hp == null) //found end { nxp = new Node (dx); return nxp; } //list not empty hp.setNext(appendRec2(hp.getNext(),dx)); return hp; }

Thank you in advance!