Question: I ' m having trouble with this. Whenever I go to test the code in the DrJava interactions pane I keep getting the error Invalid
Im having trouble with this. Whenever I go to test the code in the DrJava interactions pane I keep getting the error "Invalid reference name" and I don't know why. Help would be appreciated
Step : Start DrJava
Start DrJava or reset the interactions pane.
Step : Writing some Java code for our Linked List implementation
Enter the LLNode class into DrJava:
The node of a linked list
public class LLNode
the element stored in the node
private T element;
a reference to the next node of the list
private LLNode next;
the constructor
@param element the element to store in the node
@param next a reference to the next node of the list
public LLNodeT element, LLNode next
this.element element;
this.next next;
Returns the element stored in the node
@return the element stored in the node
public T getElement
return element;
Returns the next node of the list
@return the next node of the list
public LLNode getNext
return next;
Changes the node that comes after this node in the list
@param next the node that should come after this node in the list. It can be null.
public void setNextLLNode next
this.next next;
The rest of the code can be entered in the interactions pane. If you get an error, enter the corrected code. If you get really mixed up you can reset the interactions pane and try again.
Step : Write Java commands to create the following linked list with the variable listHead pointing to the first node of the list:
listHead X
Hint: You can do this with lines of code in the Interactions pane. For fun, try doing it with just one line! You can test it by typing listHead.getElement listHead.getNextgetElement listHead.getNextgetNextgetElement and listHead.getNextgetNextgetNext in the Interactions pane, and if your list is correct, the outputs should be and null.
In the above picture, each box refers to a single LLNode object, the left item in the box is the element and the right item is the next reference.
Step : Try to create the same linked list, but now use a loop where, in each iteration, it creates a single LLNode instance. To create the three nodes, the loop will need to iterate three times. Hint: is it easier to create the list forwards or backwards?
Submit your answer.How do i ask a chegg expert for help without the use of ai
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
