Question: Implement the Node class shown in the handout. Test the class by implementing a main method that uses each constructor and each method. Create four

 Implement the Node class shown in the handout. Test the class
by implementing a main method that uses each constructor and each method.
Create four nodes with each next variable set to nul. .. For

Implement the Node class shown in the handout. Test the class by implementing a main method that uses each constructor and each method. Create four nodes with each next variable set to nul. .. For example, Noden1=newNode(a,null); Create a 4-node linked list by setting the next variable of the one node to a different node. For example, n1. setNext (n2); The next variable for the last node should remain null. Print the contents of each node of the linked list using only the first node reference variable. For example, the contents of the second node may be accessed as follows. n1. getnext(). getItem() Set the reference variable to the second, third and fourth nodes to null. Do step 3 again. Create a new Node reference variable curr. Set it to reference the first node. For example, Nodecurr=n1; Use curr to print the contents of the first node. Now set curr to reference the second node. curr=n1.getNext(); Use curr to print the contents of the second node. Now use curr to print the contents of the remaining nodes in the linked list. Can this be done with a loop? For example, a while loop could begin with curr set to reference the first node. Once the contents of the first node are printed, curr is set to reference the next node. This continues until the last node is printed and the curr is now set to null. 6. A linked list may be built from nodes with a node reference variable to only the first node. The reference variable is typically called head. One way to build a linked list is by placing new nodes at the beginning of the list. Use the sample below to build a 4-node linked list in this manner. Print its contents after it is complete. Nodehead;//tolinkedlisthead=newNode(c,null);head=newNode(a,head);//createreferencevariable//createfirstnode//createsecondnode//pointingtofirstnode

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!