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

Please i NEED your help to complete this class class IntNode { private int data;

ID: 3651933 • Letter: P

Question


Please i NEED your help to complete this class


class IntNode
{
private int data;
private IntNode link;
public IntNode(int initialData, IntNode initialLink)
{
data = initialData;
link = initialLink;
}
public int getData( ) { return data; }
public IntNode getLink( ) { return link; }
public void setData(int newData) { data = newData; }
public void setLink(IntNode newLink) { link = newLink; }
}//IntNode



public class PracticeWithLinkedLists
{
public static void main(String[ ] args)
{

IntNode head = null;
IntNode tail = null;

// 1.) Insert a node with data 100 into this empty list.




// 2.) Insert a node with data 200 at the beginning of the list.




// 3.) Insert a node with data 300 at the end of the list.




IntNode cursor = null;
// The list now has three nodes. Move the cursor to the middle node.



// 4.) Insert a node with data 400 after the cursor (but don't move the cursor).




// The list should now be [200, 100, 400, 300], with the
// cursor still pointed at the node containing 100.

// 5.) Delete the node pointed to by the cursor. Then nullify the cursor.




// 6.) Delete the first node in the list (the one containing 200).




// 7.) Delete the last node in the list (the one containing 300).




// 8.) Delete the single remaining node from the list (the one containing 400).




// Make sure that head and tail are both null.
if ( (head != null) || (tail != null) )
System.out.println("You did something wrong.");

}//main()
}//PracticeWithLinkedLists

Explanation / Answer

public void add(int index, E elem){ /*If the user wants to add it to the end of the list call the other add() method, which is more efficient and then end this method*/ if(index == size()){ add(elem); return; } else if(index == 0){ Node temp = new Node(); temp.elem = elem; temp.next = head; head.previous = temp; head = temp; counter++; return; } /*Here, we start to see the temp node come into play. We use it to track the current node without modifying the head node. */ temp = head; for(int i = 0; i