public class MyLinkedList implements Iterable { private int theSize; private Node beginMarker; private Node endMarker; public class Node{ public Node (AnyType data, Node head, Node tail){ myData=data; myHead=head; myTail=tail; } public AnyType myData; public Node myHead; public Node myTail; } public MyLinkedList(){} public void clear(){} public int size(){ } public boolean exist(AnyType newVal){ } public boolean add(AnyType newVal){ } public boolean add(int index, AnyType newVal) { } public Node get(AnyType nodeData){} public void printList(){}; public java.util.Iterator iterator(){} public void remove(AnyType removeVal){} private class LinkedListIterator implements java.util.Iterator{ public void remove(){} public boolean hasNext() {} public AnyType next() {} } private void addBefore(Node previousNode, AnyType newNode){} private void testListIntegers(){ MyLinkedList testList = new MyLinkedList(); testList.add(new Integer(5)); testList.add(new Integer(4)); testList.add(new Integer(3)); System.out.println(" We have so far inserted " + testList.size() + " elements in the list"); testList.remove(4); System.out.println(" Now, there is only " + testList.size() + " elements left in the list"); testList.add(1, new Integer(7)); testList.add(2, new Integer(8)); System.out.println(" About to print content of the list"); testList.printList(); } private void testListStrings(){ MyLinkedList testList = new MyLinkedList(); testList.add(new String("hello")); testList.add(new String("this is")); testList.add(new String("cs3345 project 2")); System.out.println(" We have so far inserted " + testList.size() + '' elements in the list"); testList.remove("this is"); System.out.println(" Now, there is only " + testList.size() + " elements left in the list"); testList.add(1, "a modified version of"); testList.add(2, "cs3345 project 2, call it version 2" ); System.out.println(" About to print content of the list"); testList.printList(); } public static void main (String args[]) throws Exception { // Add whatever code you need here // However, you will need to call both testListIntegers() // and testListStrings() } }
Finish the coding the following double-linked list implementation (called myLinkedList) given bellow:
Most of the functions/definitions are not finished. You should code the existing functions without changing their existing definition. Also, you can add code to the main function. The goal is to show that you have a complete myLinkedList implementation. If needed, add new functions/methods to complete your implementation. Hint: Some of the definitions are already in the textbook, but might be a bit different