In the MyLinkedList class, write Java code for the followingquestion.
class MyLinkedList {
private Node firstNode; // index = 0
private int length;
public MyLinkedList() {
public boolean add(Object newEntry) { … }
public boolean add(int index, ObjectnewEntry) { … }
public boolean addAfterCurrent(Object currentEntry,Object newEntry){ … }
public boolean contains(Object anEntry) { … }
public Object getEntry(int index) { … }
public int getIndex(Object anEntry) { …}
public Object remove(int index) { … }
public Object remove(Object anEntry) { …}
public boolean replace(int index, Object newEntry) { … }
public boolean equals(Object other) { … }
public int getLength() { … }
public boolean isEmpty() { … }
public String toString() { … }
private Node getNode(int index) {… }
private class Node {
private Object data;// data portion
private Node next; //link to next node
private Node(ObjectdataPortion) { … }
private Node(ObjectdataPortion, Node nextNode) { … }
private voidsetData(Object dataPortion) { … }
private ObjectgetData() { … }
private voidsetNextNode(Node nextNode) { … }
private NodegetNextNode() { … }
} // end Node
} // end MyLinkedList
Complete themethod addAfterCurrent by adding code atthe comment labeled ADD YOUR CODE HERE. This method gets an entryin the linked list with the following header:
/** Task: Adds a new entry after current entry
* @param newEntry the object to be added aftercurrentEntry
* @return true if successful, or false if current entrynot found */
public boolean addAfterCurrent(Object currentEntry, ObjectnewEntry) {
// ADD YOUR CODE HERE
} // end addAfterCurrent
In the MyLinkedList class, write Java code for the following question. class MyLinkedList { private Node firstNode; /
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am