class InsertList1 { // A sequence type implemented using a doubly-linked list. private Cell ptr; public InsertList1() { ptr=null; } public boolean isEmpty() { return ptr==null; } public boolean atEnd() { return ptr.next==null; } public boolean atStart() { return ptr.prev==null; } public void insert(Object obj) { if(ptr==null) ptr = new Cell(null,obj,null); else if(ptr.next==null) { ptr.next = new Cell(ptr,obj,null); ptr = ptr.next; } else { ptr.next.prev = new Cell(ptr,obj,ptr.next); ptr.next = ptr.next.prev; ptr=ptr.next; } } public void delete() { if(ptr.next==null) { ptr = ptr.prev; if(ptr!=null) ptr.next=null; } else { ptr.next.prev = ptr.prev; if(ptr.prev!=null) ptr.prev.next = ptr.next; ptr=ptr.next; } } public void forward() { ptr = ptr.next; } public void backward() { ptr = ptr.prev; } public Object current() { return ptr.content; } public String toString() { Cell temp; String str=""; if(ptr!=null) { for(temp=ptr; temp.prev!=null; temp=temp.prev); for(;temp!=null;temp=temp.next) { if(temp==ptr) str+="> "; else str+=" "; str+=temp.content+"\n"; } } return str; } private static class Cell { Cell prev,next; Object content; Cell(Cell p,Object obj,Cell n) { prev=p; content=obj; next=n; } } }