Question: I need help implementing this code for my PROJECT please help. This is the requrment. : You are required to use the List interface from

I need help implementing this code for my PROJECT please help. This is the requrment. : You are required to use the List interface from the textbook. Additionally, you are required to use the Link class for doubly-linked nodes (which is different than the Link class for the practice assignments). Furthermore, you are required to start with the textbook's implementation of a doubly-linked list, the DLList class, but are not allowed to use a header node nor a trailer node (so remove the code that creates them). Name your class BasicDLList. Modify your BasicDLList class so that the results of each method are identical with those of the DLList class. Extend your MenuDriver class from Project 1 by adding in code to create a BasicDLList object and calls its methods. Additionally, add in an option for "V", that calls the BasicDLList.toString method to list all of the strings in a comma-seperated list. THis is my code I have now below, I need help with implemeting the link class,it is in the SCREENSHOT, I keep geeting errors about duplication of the class link when I submit it into an auto grade. Any changes made are welcome aslong as they follow the above requirments Thank you. class Link import java.util.NoSuchElementException;
public class BasicDLList implements List {
private Link head; // Pointer to first element
private Link tail; // Pointer to last element
private Link curr; // Access to current element
private int listSize; // Size of list
public BasicDLList(){
clear();
}
public void clear(){
head = tail = curr = null; // No header or trailer
listSize =0;
}
public boolean insert(E it){
if (curr == null){// List is empty
curr = head = tail = new Link(it, null, null);
} else {
Link tmp = new Link(it, curr.prev(), curr);
if (curr.prev()!= null){
curr.prev().setNext(tmp);
} else {
head = tmp;
}
curr.setPrev(tmp);
if (curr == head){
head = tmp;
}
}
listSize++;
return true;
}
public boolean append(E it){
if (tail == null){// List is empty
curr = head = tail = new Link(it, null, null);
} else {
Link tmp = new Link(it, tail, null);
tail.setNext(tmp);
tail = tmp;
}
listSize++;
return true;
}
public E remove() throws NoSuchElementException {
if (curr == null){
throw new NoSuchElementException("List is empty.");
}
E it = curr.element();
if (curr == head){
head = head.next();
if (head != null){
head.setPrev(null);
}
} else if (curr == tail){
tail = tail.prev();
tail.setNext(null);
} else {
curr.prev().setNext(curr.next());
curr.next().setPrev(curr.prev());
}
if (curr == tail){
curr = null; // Removed last element
} else {
curr = curr.next();
}
listSize--;
return it;
}
public void moveToStart(){
curr = head;
}
public void moveToEnd(){
curr = tail;
}
public void prev(){
if (curr != head){
curr = curr.prev();
}
}
public void next(){
if (curr != tail){
curr = curr.next();
}
}
public int length(){
return listSize;
}
public int currPos(){
Link temp = head;
int i;
for (i =0; temp != null && temp != curr; i++){
temp = temp.next();
}
return i;
}
public boolean moveToPos(int pos){
if (pos 0|| pos >= listSize){
return false;
}
curr = head;
for (int i =0; i pos; i++){
curr = curr.next();
}
return true;
}
public boolean isAtEnd(){
return curr == tail;
}
public E getValue() throws NoSuchElementException {
if (curr == null){
throw new NoSuchElementException("No current element.");
}
return curr.element();
}
public boolean isEmpty(){
return listSize ==0;
}
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append("|");
Link temp = head;
while (temp != null){
sb.append(temp.element());
if (temp.next()!= null){
sb.append(",");
}
temp = temp.next();
}
sb.append("");
return sb.toString();
}
}
 I need help implementing this code for my PROJECT please help.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!