Question: JAVA Add the following method to LinkedList.java.Method public void addAsSecondNode(String d)that will add a new Node to the linked list with String d as the

JAVA Add the following method to LinkedList.java.Method public void addAsSecondNode(String d)that will add a new Node to the linked list with String d as the second node in the list. If the list is empty, it will add it as the first node.

JAVA Add the following method to LinkedList.java.Method public void addAsSecondNode(String d)that will

/class Node public class Nod private String data;private Node next;public Kode String d, Node n)i data d; next = n ; public String getata) return data; public Node getiexti) return nexti public void Data LS tring d)( data = d;} public void etiext node n){ next = n; } public string return data> sostting(){ /class tinkedtist (only the first few methods are given here) public class tinkedtists private Node front; private jnt count; //constructor public Tinkedtist) front - null; count 0; /fadd a node to the front of the linked list public void addRoErontistring d)i Node n; n# new Nodeld, front): front -n;count++; //get the current size of the list public int sizet)i return count; h //check if the list is empty public baaleandAR nRARL) { return (count 0); } /clear the 1ist public void glearf)( front null; count-o; } //get the content of the first node public String getErontlatai) 1 if (front--null) return Empty list else return /ew method added - get the first node public Node getRrRD) i return front; //scan the list and print contents public void eniimeratei) i Kode cu = front; while (surxenull) i Curx)

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!