Write the code necessary to convert the following sequence of ListNode objects:
ID: 3869191 • Letter: W
Question
Write the code necessary to convert the following sequence of ListNode objects: list rightarrow [1] rightarrow [2] rightarrow [3] Into these sequences of ListNode objects: list rightarrow [2]/list2 rightarrow [1] rightarrow [3]/Assume that you are using ListNode class as defined in the textbook: public class ListNode { public int data;//data stored in this node public ListNode next;//a link to the next node in the list public ListNode() {...) public ListNode (int data) {...} public ListNode (int data, ListNode next) {) }Explanation / Answer
class List{
private ListNode head;
public List(){head = null;}
public void insertFront (int obj)
{
head = new ListNode(onj, head);
}
// other methods to be declared
public boolean isEmpty(){...}
public Object removeFront() {...}
public Object removeBack(){...}
public void insertBack(Object value){...}
public ListNode nth(int i){...}
public void insertAfter(ListNode node, Object value){...}
}
public class ListNode{
public Object item;
public ListNode next;
public ListNode(Object value){item = value;}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.