// driver - create a double linked list: "Jon", "Lee", "Smith" class DListNodeDemo { public static void main(String[] args) { DListNode middle = new DListNode("Lee", null, null); DListNode head = new DListNode("Jon", middle, null); middle.setBack(head); DListNode end = new DListNode("Smith", null, middle); middle.setNext(end); // insert "Jon" to the front and let head point to it DListNode temp = new DListNode("Adam", head, null); head.setBack(temp); // head = temp; // head = head.getBack(); head = head.getBack(); // insert "Willi" to the end of the list and let end point to it temp = new DListNode("Willi", null, end); end.setNext(temp); end = temp; // insert "Chris" between "Adam" and "Jon" DListNode t = head.getNext(); // the "Jon" node temp = new DListNode("Chris", t, head); // Step A head.setNext(temp); // Step B t.setBack(temp); // Step C /* System.out.println(head.getData()); System.out.println(head.getNext().getData()); System.out.println(head.getNext().getNext().getData()); System.out.println(head.getNext().getNext().getNext().getData()); System.out.println(head.getNext().getNext().getNext().getNext().getData()); System.out.println(head.getNext().getNext().getNext().getNext().getNext().getData()); */ System.out.println(end.getBack().getBack().getBack().getBack().getBack().getData()); System.out.println(end.getBack().getBack().getBack().getBack().getData()); System.out.println(end.getBack().getBack().getBack().getData()); System.out.println(end.getBack().getBack().getData()); System.out.println(end.getBack().getData()); System.out.println(end.getData()); } }