Question: Question 3 Consider the following linked list, where head is the reference to the beginning node. class Node { public String data; / / data

Question 3
Consider the following linked list, where head is the reference to the beginning node.
class Node
{
public String data; // data in the node
public Node next; // reference to the successor
public Node (String d)
{
data = d;
next = null;
}
}
class LinkedList
{
private Node head; // reference to the beginning node
public LinkedList()
{
head = null;
}
public void insertAsFirstNode(String d)
{
// your code comes here ...
}
public void insertAsLastNode(String d)
{
// your code comes here ...
}
}
Implement the following two functions. Do NOT use any other helper class/object such as class ReferencePair in Example08SortedLinkedList.
(4 Points) Implement function insertAsFirstNode(String d) to insert a new node, whose data field is d, as the beginning node of the linked list.
(6 Points) Implement function insertAsLastNode(String d) to insert a new node, whose data field is d, as the ending node of the linked list.

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 Programming Questions!