package dk.itu.oop.lecture5; public class StringList { private ListElement head; private ListElement tail; private class ListElement{ private String value; private ListElement next; ListElement(String val, ListElement elm){ value = val; next = elm; } ListElement(String val){ this(val,null); } } public boolean isEmpty(){ return head == null; } public void insertFirst(String s){ head = new ListElement(s,head); if (tail == null) tail = head; } public void insertLast(String s){ ListElement newOne = new ListElement(s); if (head == null) head = tail = newOne; else tail = tail.next = new ListElement(s); } public void insertInOrder(String s){ if ( isEmpty() ) insertFirst(s); else { ListElement before=null; ListElement after =head; while(after != null && after.value.compareToIgnoreCase(s)<0 ){ // all elements from head to before (not incl) are less than s // after is the element after before before = after; after = after.next; } if (before == null) head = new ListElement(s,head); else before.next = new ListElement(s,after); } } }