Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using java The class GenDoubleLinkedList needs to have the following: Internal c

ID: 3884592 • Letter: U

Question

Using java

The class GenDoubleLinkedList needs to have the following: Internal class ListNode which has Instance Variables data of type T nextLink of tvpe ListNode prevLink of type ListNode Constructors Default Parameterized Instance Variables head of type ListNode which always points to the beginning of the linked list current of type ListNode which moves around pointing to one of the nodes Constructor A default constructor that initializes head to an empty ListNode and sets current to point at the head. Methods goToNext - This moves the current node forward in the list by one node. It doesn't move forward if that node is null goToPrev - This moves the current node backwards in the list by one node. It doesn't move backwards if that node is null. getDataAtCurrent - returns the data at the current node as long as the current isn't null setDataAtCurrent takes in a parameter and sets the data at the current node to that value as long as current is not null insertNodeAfte

Explanation / Answer

/* This is the class asked in question for implementation. */
class GenDoubleLinkedList<T>
{
/* Instance Variables */
ListNode head;
ListNode current;

/* Constructor which initialises head to empty and current to head */
GenDoubleLinkedList()
{
head = null;
current = head;
}

/* Internal Class */
class ListNode
{
T data;
ListNode nextLink;
ListNode prevLink;

/* Default Constructot */
ListNode()
{
this.nextLink = null;
this.prevLink = null;
}
/* Parameterised Constructor */
ListNode(T Element, ListNode next, ListNode prev)
{
this.data = Element;
this.nextLink = next;
this.prevLink = prev;
}
}

/* goToNext method */
public void goToNext()
{
if(current.nextLink != null)
{
current = current.nextLink;
}
}

/* goToPrev method */
public void goToPrev()
{
if(current.prevLink != null)
{
current = current.prevLink;
}
}

/* getDataAtCurrent method */
public void getDataAtCurrent()
{
if(current != null)
{
System.out.println("Current data is : "+current.data);
}
}

/* setDataAtCurrent method */
public void setDataAtCurrent(T element)
{
if(current != null)
{
current.data = element;
}
}

/* insertNodeAfterCurrent method */
public void insertNodeAfterCurrent(T element)
{
ListNode tmp = new ListNode(element, null, null);
if(current == null)
{
head = tmp;
tmp.nextLink = null;
current = head;
}
else
{
tmp.prevLink = current;
tmp.nextLink = current.nextLink;

if(current.nextLink != null)
{
current.nextLink.prevLink = tmp;
}

current.nextLink = tmp;
}
}

/* deleteCurrentNode */
public void deleteCurrentNode()
{
if(current == null) // if list is null
{
System.out.println("List is already empty.");
}
else if(current == head) // if 1st element is deleted
{
head = head.nextLink;
if(head != null)
{
head.prevLink = null;
}
current = head;
}
else // if any other element is deleted
{
ListNode tmp = current;
tmp.prevLink.nextLink = tmp.nextLink;
if(tmp.nextLink != null)
{
tmp.nextLink.prevLink = tmp.prevLink;
}
current = tmp.prevLink;
}
}

/* showList method */
public void showList()
{
ListNode tmp = head;
if(head == null)
{
System.out.println("List is empty");
return;
}
while(tmp != null)
{
System.out.println(tmp.data);
tmp = tmp.nextLink;
}
}

/*inList method */
public boolean inList(T element)
{
ListNode tmp = head;
while(tmp != null)
{
if(tmp.data == element)
{
return true;
}
tmp = tmp.nextLink;
}

return false;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote