import java.io.*; class Editor1 { // A simple text editor program public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); InsertList2 lines = new InsertList2(); char ch; String command,line; do { System.out.print(": "); command = in.readLine(); ch = command.charAt(0); switch(ch) { case 'i' : do { line = in.readLine(); if(line.length()==1&&line.charAt(0)=='.') break; lines.insert(line); } while(true); break; case 'd' : if(lines.isEmpty()) System.out.println("?"); else { lines.delete(); if(!lines.isEmpty()) System.out.println(lines.current()); } break; case '+' : if(lines.isEmpty()||lines.atEnd()) System.out.println("?"); else { lines.forward(); System.out.println(lines.current()); } break; case '-' : if(lines.isEmpty()||lines.atStart()) System.out.println("?"); else { lines.backward(); System.out.println(lines.current()); } break; case 'p': if(lines.isEmpty()) System.out.println("?"); else System.out.println(lines.current()); break; case 'l': System.out.print(lines); break; case 'q': break; default: System.out.println("?"); } } while(ch!='q'); } }