import java.util.Scanner; import java.io.*; import javax.swing.JOptionPane; public class DoubleLinked { public static void main(String[] args) throws FileNotFoundException { DLNode head=new DLNode("",null,null); insert(head,"A"); insert(head,"B"); insert(head,"C"); insert(head,"D"); print(head); } public static void print(DLNode head) { System.out.print("["); while(head != null) { System.out.print(head.getValue()); if(head.getPrev()!=null) System.out.print(", "); head = head.getPrev(); } System.out.println("]"); } public static void insert(DLNode t, Object obj) { if(t==null) { t = new DLNode(obj, null, null); } else if(t.getNext()==null) { System.out.print("FME2 "+obj); t.setNext(new DLNode(obj,t,null)); } else { System.out.print("FME3 "+obj); DLNode cool=new DLNode(obj,t,t.getNext()); t.getNext().setPrev(cool); t.setNext(cool); } } public static void remove(DLNode t) { if(t.getPrev()==null) t.getNext().setPrev(null); else if(t.getNext()==null) t.getPrev().setNext(null); else { t.getPrev().setNext(t.getNext()); t.getNext().setPrev(t.getPrev()); } } }