Question: if we have following List classes: class Node { T value; Node next; ... } class LinkedList { private Node head; ... } can you
if we have following List classes:
class Node
{
T value;
Node next;
...
}
class LinkedList {
private Node head;
... }
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
Get step-by-step solutions from verified subject matter experts
