Question
if we have following List classes: public class LinkedList { class ListNode { protected T value; protected ListNode next; public ListNode(T val, ListNode nxt) {
if we have following List classes:
public class LinkedList
class ListNode {
protected T value;
protected ListNode next;
public ListNode(T val, ListNode nxt) {
value = val;
next = nxt;
}
public ListNode(T val) {
this(val, null);
}
public ListNode() {
this(null, null);
}
}
can you write the folowing methods in java:
1.Write a method for the LinkedList class called int indexOf(T val) which returns the integer index indicating the location of val in the list, or -1 if val is not in the list.
2. Write a method for the LinkedList class called boolean equals(LinkedList rhs) which checks for deep equality, i.e. checks if rhs and the receiving object store the same values in the same order.
3. Assume that the method described in Problem 3 does not exist. Write a method boolean equals(LinkedList lhs, LinkedList rhs) that uses two ListIterators to check for deep equality of lists lhs and rhs. This code should NOT be part of the ListIterator class.
4. Write a recursive method void printReverse(Node node) which prints the values in the list referenced by node in reverse. You may assume that node references a valid node in the list, i.e. not the dummy header node. HINT: this method should only be 3 or 4 lines long.
5. Write a method for the LinkedList class called boolean removeLast(T val) which removes the last occurrence of val from the list. The method should return true if it is successful.
6. Repeat the previous problem using a doubly linked list.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started