In Java: 001 package algs13; 002 import java.text. DecimalFormat; 003 import stdlib.*; 004 005 006 * Complete
Fantastic news! We've Found the answer you've been seeking!
Question:
In Java:
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Understanding Basic Statistics
ISBN: 9781111827021
6th Edition
Authors: Charles Henry Brase, Corrinne Pellillo Brase
Posted Date:
Students also viewed these programming questions
-
Consider a binomial distribution with n = 5 trials. Use the probabilities given in Table 2 of the Appendix to make histograms showing the probabilities of r = 0, 1, 2, 3, 4, and 5 successes for each...
-
Consider a binomial distribution with 10 trials. Look at Table 2 in the Appendix showing binomial probabilities for various values of p, the probability of success on a single trial. (a) For what...
-
QUESTION 9 The output expression for an AND-OR-Invert circuit having one AND gate with inputs A, B and C and one AND gate with inputs D, E and Fis O(A+B+C)(D+E+F) O (A+B+C)(D+E+F) ABC + DEF...
-
Doctor Bones prescribed physical therapy in a pool to treat Jack's broken back. In response to this advice (and for no other reason), Jack built a swimming pool in his backyard and strictly limited...
-
The following data represent the percentage of total federal debt held by the public as a percentage of gross domestic product (GDP). The GDP of a country is the total value of all goods and services...
-
The degree of freedom of a system comprising a gaseous mixture of \(\mathrm{H}_{2}\) and \(\mathrm{NH}_{3}\) will be (a) 1 (c) 3 (b) 2 (d) 0
-
Loxley Corporation is authorized to issue 50,000 shares of $10 par value common stock. During 2010, Loxley took part in the following selected transactions. 1. Issued 5,000 shares of stock at $45 per...
-
2.34 Find the following sum by first creating vectors for the numerators and denominators: 3 5 7 9 ++ +- 1 2 3 4
-
A particle suspension contains equal numbers of spherical sand particles (specific gravity 2.65) in each of the following particle diameters: 0.085 mm, 0.070 mm, 0.060 mm, 0.005 mm. Design a 2-m deep...
-
What are the benefits of free trade?
-
What is GDP and why is it important?
-
Explain the law of demand and provide an example.
-
A car accelerates from rest to a velocity of 25 m/s in 5 seconds. What is its acceleration during this time period?
-
Healthcare professionals needs to compare their standards with international providers who have been recognized tom offer the best care. Outline the procedure involved in the comparison and its...
-
Julio runs a 100-meter race. 7 seconds after the race started. Julio is 35 meters from the starting line and reaches his max speed; he runs at this max speed for the rest of the race. Julio notices...
-
Show that every group G with identity e and such that x * x = e for all x G is abelian.
-
For a site chosen at random, estimate the following probabilities. (a) P(0 x < 30) (b) P(10 x , 40) (c) P(x < 20) (d) P(x 20) (e) P(30 x) (f) P(x not less than 10) (g) P(0 x < 10 or 40 x) (h)...
-
Make a stem-and-leaf display. Use five lines per stem so that leaf values 0 and 1 are on one line, 2 and 3 are on the next line, 4 and 5 are on the next, 6 and 7 are on the next, and 8 and 9 are on...
-
Consider the following events for a college student selected at random: A = student is female B = student is majoring in business Translate each of the following phrases into symbols: (a) The...
-
What are the resources of the organization? How are these used in management decision making?
-
Define management and indicate what its principal purposes are and why managers are essential to organizations.
-
Through the implementation of efficient and effective management, New Belgium Brewing (NBB) has grown from operating out of the founder's basement to having two state-of-the-art facilities and over...
Study smarter with the SolutionInn App