package linkedLists; public class SGenLinkedList { /** Generic singly linked list with just a head*/ private SNodeGen head; //head node of the list /** Default constructor that creates an empty list */ public SGenLinkedList(){ head=null; } /**return the head of the list*/ public SNodeGen getHead(){ return head; } /**set the head of the list*/ public void setHead(SNodeGen n){ head=n; } /**is the list empty?*/ public boolean isEmpty(){ return(head==null); } /**add a new node at front of list */ public void addFirst(SNodeGen n){ n.setNext(head); head=n; } /** remove node from front of list */ public void removeFirst(){ if (!isEmpty()) head=head.getNext(); else System.out.println("Can't remove from list, list is empty"); } /** String representation of list */ public String toString(){ SNodeGen temp=head; String myString=""; while(temp!=null){ myString=myString + temp.getElement()+" "; temp=temp.getNext(); } return myString; } }