Question: In Java: 001 package algs13; 002 import java.text. DecimalFormat; 003 import stdlib.*; 004 005 006 * Complete the methods below. 007 * All of these

In Java:


 001 package algs13; 002 import java.text. DecimalFormat; 003 import stdlib.*; 004 005

006 * Complete the methods below. 007 * All of these methods

modify the list. 008 009 010 011 012 * Use the function

check Invariants to ensure that your list is well-formed after you modify

it. * Note that this list keeps track of the number of  
 
 
 

001 package algs13; 002 import java.text. DecimalFormat; 003 import stdlib.*; 004 005 006 * Complete the methods below. 007 * All of these methods modify the list. 008 009 010 011 012 * Use the function check Invariants 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. 013 * You may not add any methods to the node class. 014 * You may not create any new objects objects. 015 * For example, you may not create a new Node, new Stack, or new ArrayList. 016 * 017 * new Node (...) // Forbidden: create a new Node object. 018 * 019 020 * * You *may* declare variables of type Node. Node x = first; // Allowed: declare variable of type Node. 021 022 * 023 * You may not change the item value of any existing node, only change the next pointer. 024 * 025 * 026 * x.item ... // Forbidden x.next... // Allowed 027 * first 028 * // Allowed 029 * Each function must be independent. 030 031 * For example, you cannot call delete to implement remove. * You MAY add private methods to the list class (helper functions for the recursion). 032 * You do NOT need to use recursion for this homework. 033 * You can use Loops in each problem. 034 */ 035 public class MyLinked2 { static class Node { 036 037 038 039 040 } public Node (double item, Node next) { this.item = item; this.next next; } public double item; public Node next; 041 int N; 042 Node first; 043 044 045 046 047 048 049 // delete the kth element (where k is between 0 and N-1 inclusive) public void delete (int k) { } if (k|| k >= N) throw new IllegalArgumentException (); // TODO // reverse the list "in place"... public void reverse () { 050 051 052 053 054 } 055 056 057 058 } 059 // TODO // remove all occurrences of item from the List public void remove (double item) { // TODO

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 Programming Questions!