// UnsortedList.java // implementation // public class UnsortedList { private int length; private ListNode head; private ListNode currentPos; public UnsortedList() { length = 0; head = null; currentPos = null; } public boolean isEmpty() { return length==0; } public void insert(String item) // to front of the list { length ++; ListNode temp = new ListNode(item, null); if(isEmpty()) { head = temp; currentPos = temp; } else { temp.setLink(head); head = temp; currentPos = temp; } } public void printFrom(ListNode temp) { //ListNode temp = currentPos; System.out.println("The list is: "); while(temp != null) { System.out.print(temp.getData() + " "); temp = temp.getLink(); } System.out.println(); } public void Print() { printFrom(head); } public String getCurentItem() { return currentPos.getData(); } public String getNextItem() { ListNode temp = currentPos; temp = temp.getLink(); return temp.getData(); } public boolean search(String item) { boolean find = false; ListNode temp = head; while(temp != null) { if(temp.getData().equalsIgnoreCase(item)) { find = true; currentPos = temp; } // move one node forward temp = temp.getLink(); } return find; } }