class InsertList2 { // A sequence type implemented using two singly-linked lists. private Cell before,after; public InsertList2() { before=null; after=null; } public boolean isEmpty() { return before==null&&after==null; } public boolean atEnd() { return after==null; } public boolean atStart() { return before.next==null; } public void insert(Object obj) { before = new Cell(obj,before); } public void delete() { before = before.next; } public void forward() { Cell ptr=after; after=after.next; ptr.next=before; before=ptr; } public void backward() { Cell ptr=before; before=before.next; ptr.next=after; after=ptr; } public Object current() { return before.content; } public String toString() { Cell ptr; String str=""; if(before==null) return ""; for(ptr=before.next; ptr!=null; ptr=ptr.next) str=" "+ptr.content+"\n"+str; str=str+"> "+before.content+"\n"; for(ptr=after; ptr!=null; ptr=ptr.next) str=str+" "+ptr.content+"\n"; return str; } private static class Cell { Cell next; Object content; Cell(Object obj,Cell n) { content=obj; next=n; } } }