myLinkedList.java>>>>>>>> public class MyLinkedList implements MiniList<Integer>{ /* Private member variables that you need to declare: ** The head pointer **...

50.1K

Verified Solution

Question

Programming

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.

Answer & Explanation Solved by verified expert
4.2 Ratings (696 Votes)
OUTPUT I have added an own display function for testing Feelfree to remove thatCODE Tried my best tocover all the functions and appropriate return types Kindly upvoteif this helped you Define you own package at the top if neededpublic class MyLinkedList implements MiniList Integer Private member variables that you need to declare The head pointer The tail pointer class Node Integer data Node next public Nodeint data thisdata data thisnext null public Node h public Node t Initialize the linked list set head and tail pointers public MyLinkedList h null t null Override public boolean addInteger item Node newNode new Nodeitem if h null h newNode t newNode else tnext newNode t newNode return true Override public void addint index Integer element Node current h if h null return int count 0 while current null if index 1 count Node newNode new Nodeelement newNodenext currentnext currentnext    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students