Question
package algs13; import java.text.DecimalFormat; import stdlib.*; /* * Complete the methods below. * All of these methods modify the list. * Use the function checkInvariants
package algs13; import java.text.DecimalFormat; import stdlib.*;
/* * Complete the methods below. * All of these methods modify the list. * Use the function checkInvariants to ensure that your list is well-formed after you modify it. * Note that this list keeps track of the number of elements N. * It is important that N accurately reflect the length of the list. * * You may not add any fields to the node or list classes. * You may not add any methods to the node class. * You may not create any new nodes or other objects. * For example, you cannot create a new Stack or ArrayList. * * Each function must be independent. * For example, you cannot call delete to implement remove. * You MAY add private methods to the list class (helper functions for the recursion). */ public class MyLinked2 { static class Node { public Node (double item, Node next) { this.item = item; this.next = next; } public double item; public Node next; } int N; Node first;
// delete the kth element (where k is between 0 and N-1 inclusive) public void delete (int k) { if (k = N) throw new IllegalArgumentException (); // TODO }
// reverse the list "in place"... public void reverse () { // TODO }
// remove all occurrences of item from the list public void remove (double item) { // TODO }
import java.text.DecimalFormat; Complete the methods below. All of these methods modify the list. Use the function checkInvariants to ensure that your list is well-formed after you modify it. Note that this list keeps track of the number of elements N. It is important that N accurately reflect the length of the list. You may not add any fields to the node or list classes. You may not add any methods to the node class. You may not create any new nodes or other objects. For example, you cannot create a new Stack or ArrayList Each function must be independent. For example, you cannot call delete to implement remove. You MAY add private methods to the list class (helper functions for the recursion) public class MyLinked2 { e static class Node { public Node (double item, Node next) public double item; public Node next this.itemitem; this.next-next; int N; Node first; // delete the kth element (where k is between0 and N-1 inclusive) e public void delete (int k) if (k 0 11 k >= N) throw new IllegalArgumentException (); // TODO // reverse the list "in place"... e public void reverse () { /I TODO // remove all occurrences of item from the list e public void remove (double item) { // TODOStep 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