@@ -0,0 +1,1864 @@
+package comp2402a3;%0A%0A%0A/**%0A * An implementation of the List interface as a doubly-linked circular list. A%0A * dummy node is used to simplify the code. This version has a reverse method.%0A * %0A * @param %3CT%3E%0A *            the type of elements stored in the list%0A */%0Apublic class DLListReversible%3CT%3E extends DLList%3CT%3E %7B%0A%09%0A%09/**%0A%09 * Reverses the order of the items in the list%0A%09 */%0A%09public void reverse() %7B%0A%09%09%0A%09%09if(size() %3E 1) %7B%0A%09%09%09// Begin by swapping the head and tail of the list%0A%09%09%09swapPointers(dummy);%0A%09%09%09%0A%09%09%09// newFirst is pointing to what used to be the end of the list%0A%09%09%09Node newFirst = dummy.next;%0A%09%09%09%0A%09%09%09// newLast is pointing to what used to be the beginning of the list%0A%09%09%09Node newLast = dummy.prev;%0A%0A%09%09%09int count = 0;%0A%09%09%09int limit = (int)(size() / 2);%0A%09%09%09%0A%09%09%09// Loop about size() / 2 times%0A%09%09%09while(count %3C limit) %7B%0A%09%09%09%09swapPointers(newFirst);%0A%09%09%09%09swapPointers(newLast);%0A%09%09%09%09%0A%09%09%09%09%0A%09%09%09%09newFirst = newFirst.next;%0A%09%09%09%09newLast = newLast.prev;%0A%09%09%09%09if(newFirst == newLast) %7B%0A%09%09%09%09%09// This means that the nodes are exactly in the middle of the list%0A%09%09%09%09%09// This will only happen if the list has an odd number of elements%0A%09%09%09%09%09%0A%09%09%09%09%09// Swap using either reference%0A%09%09%09%09%09swapPointers(newFirst);%0A%09%09%09%09%09%0A%09%09%09%09%09// Finished reversing the list, so just exit the loop%0A%09%09%09%09%09break;%0A%09%09%09%09%7D%0A%09%09%09%09count++;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%7D%0A%0A%09%7D%0A%09%0A%09// Helper method that just swaps the next and previous pointers of a node%0A%09private void swapPointers(Node node) %7B%0A%09%09Node temp = node.next;%0A%09%09node.next = node.prev;%0A%09%09node.prev = temp;%0A%09%7D%0A%0A%09public static void main(String%5B%5D args)%7B%0A%09%09%0A%09%09DLList%3CCharacter%3E list = new DLListReversible%3CCharacter%3E();%0A%09%09%0A%09%09String datasequence = %22ABCDEFGHIJKLMNOPQRSTUVWXYZ%22;%0A%09%09for (int i = 0; i %3C datasequence.length(); i++)%7B%0A%09%09%09list.add(datasequence.charAt(i));%0A%09%09%7D%0A%0A%09%09System.out.println(list);%0A%09%09%0A%09%09((DLListReversible%3CCharacter%3E)list).reverse();%0A%0A%09%09System.out.println(list);%0A%0A%09%7D%0A%7D%0A

Create DLListReversible class