myLinkedList.java>>>>>>>>
public class MyLinkedList implementsMiniList{
/* Private member variables that you need to declare:
** The head pointer
** The tail pointer
*/
public class Node {
// declare member variables (data and next)
// finish these constructors
public Node(int data, Node next) {}
public Node(int data) {} // HINT: use this() with next = null
}
// Initialize the linked list (set head and tail pointers)
public MyLinkedList() {}
@Override
public boolean add(Integer item) {
return false;
}
@Override
public void add(int index, Integer element) {
}
@Override
public Integer remove() {
return null;
}
@Override
public Integer remove(int index) {
return null;
}
@Override
public boolean remove(Integer item) {
return false;
}
@Override
public void clear() {
}
@Override
public boolean contains(Integer item) {
return false;
}
@Override
public Integer get(int index) {
return null;
}
@Override
public int indexOf(Integer item) {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public int size() {
return 0;
}
// Uncomment when ready to test
// @Override
// public String toString() {
// String ret = \"\";
// Node curr = head;
// while (curr != null) {
// ret += curr.data + \" \";
// curr = curr.next;
// }
// return ret;
// }
}
------------------------------------------------------------------------------------
MiniList.java>>>>>>>>
public interface MiniList {
public boolean add(E item);
public void add(int index, E element);
public E remove();
public E remove(int index);
public boolean remove(E item);
public void clear();
public boolean contains(E item);
public boolean equals(Object o);
public E get(int index);
public int indexOf(E item);
public boolean isEmpty();
public int size();
}
--------------------------------------------------------------------------------------------
LLTest.java>>>>>>>>>>>>>>>>>>>>>>>>
public class LLTest {
public static void main(String args[]) {
MyLinkedList ll = new MyLinkedList();
// Testing add methods
System.out.println(\"Testing Add\");
ll.add(40);
ll.add(10);
ll.add(20);
ll.add(1, 30);
ll.add(3, 100);
ll.add(65);
ll.add(2);
System.out.println(\"Expected: 40 30 10 100 20 65 2\");
System.out.println(\"Actual: \" + ll);
System.out.println();
// Testing remove methods
System.out.println(\"Testing Remove\");
ll.remove();
ll.remove(2);
ll.remove(3);
ll.remove((Integer)2);
System.out.println(\"Expected: 30 10 20\");
System.out.println(\"Actual: \" + ll);
System.out.println(\"Size should be 3 -> \" + ll.size());
System.out.println();
// Testing Contains
System.out.println(\"Testing Contains\");
ll.add(2); // to make it a little bigger
System.out.println(\"Should be true -> \" + ll.contains(2));
System.out.println(\"Should be false -> \" +ll.contains(65));
System.out.println(\"Should be true -> \" +ll.contains(30));
System.out.println();
// Testing Get
System.out.println(\"Testing Get\");
System.out.println(\"Actual list: \" + ll);
System.out.print(\"List using get: \");
for (int i = 0; i < ll.size(); i++) {
System.out.print(ll.get(i) + \" \");
}
System.out.println(\"\n\");
// Testing indexOf
System.out.println(\"Testing indexOf\");
System.out.println(\"Should be 2 -> \" + ll.indexOf(20));
System.out.println(\"Should be 3 -> \" + ll.indexOf(2));
System.out.println(\"Should be -1 -> \" + ll.indexOf(65));
// You can write more tests (these are not allencompassing)
// When should these methods fail/throw exceptions?
// Have all of the edge cases been tested?
// Not quite all of the methods have been tested here (e.g.clear())
}
}
----------------------------------------------------------------------------------
directions-
complete all of the methods in the the given MiniList interface.The documentation for these methods match the ones in Oracle'sdocumentation for a linked list
write the node class which should contain two member variables:data and next.