write a program that implements a variant of a linked list. This variant has a dummy...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
write a program that implements a variant of a linked list. This variant has a dummy node pointed to by the head link as shown in the following figure: Linked list with a dummy first node: item next item next item next head size = 2 -3 17 This trick will allow your code to be a little simpler, not requiring a special case for add or remove operations at index 0. Your constructor method will be: public LinkedList(X head = new Node(null); size = 0; You need to write a class called Linkedlist that implements the following List interface: // a list interface public interface List { public boolean isEmpty(); // returns true if the list is empty, false otherwise public int size(); // returns the number of items in the list public void add(Object item); // adds an item to the list // precondition: none // postcondition: item is added at the end of the list public void add (int index, Object item); // adds an item to the list at the given index // precondition: none // postcondition: item is added at the given index; // the indices of following items are increased by 1. public void remove(int index); // removes the item from the list that has the given index // precondition: none // postcondition: removes the first item in the list whose equl method // matches that of the given item public void remove (Object item); // removes an item from the list // precondition: none // postcondition: removes the first item in the list whose equal method // matches that of the given item; the indices of the following items are // decreased by 1 public List duplicate(); // creates a duplicate of the list // precondition: none // postcondition: returns a copy of the linked list public List duplicateReversed (); // creates a duplicate of the list with the nodes in reverse order // precondition: none // postcondition: returns a copy of the linked list with the nodes in // reverse order In addition to the interface, your LinkedList class needs to implement a toString() method that prints the list in the format In addition to the interface, your LinkedList class needs to implement a toString() method that prints the list in the format [ size: the size_of_the list item1, item2, .... ] Specifications, notes, and hints Your program needs to meet the following specifications: Submit the file LinkedList.java. Your Node class should be an inner class within the LinkedList class. Make sure your class implements the interface as specified, i.e. your class should begin with public class LinkedList implements List. • None of your methods should contain a test for the index being equal to 0, as the point is to have a simpler implementation. • When commenting your code use Javadoc style comments at the beginning of each method. • Put comments at the top of the file with your name, EID, email address, date and course, and a short (one or two line) description of what the program does. We will be testing the code on the machines in the CS computer lab, so make sure your code runs on those machines. Submit your source code files via the checkin program by the due date (read the course syllabus for the late policy). write a program that implements a variant of a linked list. This variant has a dummy node pointed to by the head link as shown in the following figure: Linked list with a dummy first node: item next item next item next head size = 2 -3 17 This trick will allow your code to be a little simpler, not requiring a special case for add or remove operations at index 0. Your constructor method will be: public LinkedList(X head = new Node(null); size = 0; You need to write a class called Linkedlist that implements the following List interface: // a list interface public interface List { public boolean isEmpty(); // returns true if the list is empty, false otherwise public int size(); // returns the number of items in the list public void add(Object item); // adds an item to the list // precondition: none // postcondition: item is added at the end of the list public void add (int index, Object item); // adds an item to the list at the given index // precondition: none // postcondition: item is added at the given index; // the indices of following items are increased by 1. public void remove(int index); // removes the item from the list that has the given index // precondition: none // postcondition: removes the first item in the list whose equl method // matches that of the given item public void remove (Object item); // removes an item from the list // precondition: none // postcondition: removes the first item in the list whose equal method // matches that of the given item; the indices of the following items are // decreased by 1 public List duplicate(); // creates a duplicate of the list // precondition: none // postcondition: returns a copy of the linked list public List duplicateReversed (); // creates a duplicate of the list with the nodes in reverse order // precondition: none // postcondition: returns a copy of the linked list with the nodes in // reverse order In addition to the interface, your LinkedList class needs to implement a toString() method that prints the list in the format In addition to the interface, your LinkedList class needs to implement a toString() method that prints the list in the format [ size: the size_of_the list item1, item2, .... ] Specifications, notes, and hints Your program needs to meet the following specifications: Submit the file LinkedList.java. Your Node class should be an inner class within the LinkedList class. Make sure your class implements the interface as specified, i.e. your class should begin with public class LinkedList implements List. • None of your methods should contain a test for the index being equal to 0, as the point is to have a simpler implementation. • When commenting your code use Javadoc style comments at the beginning of each method. • Put comments at the top of the file with your name, EID, email address, date and course, and a short (one or two line) description of what the program does. We will be testing the code on the machines in the CS computer lab, so make sure your code runs on those machines. Submit your source code files via the checkin program by the due date (read the course syllabus for the late policy).
Expert Answer:
Answer rating: 100% (QA)
code in java interface List public boolean isEmpty returns true if list is empty false otherwise public int size returns the number of items in the list public void addObject item adds an item in the ... View the full answer
Related Book For
Digital Signal Processing
ISBN: ?978-0133737622
3rd Edition
Authors: Jonh G. Proakis, Dimitris G.Manolakis
Posted Date:
Students also viewed these programming questions
-
In this task you will write a program in MARIE assembly language, to work out if a given year is leap year or not. Leap years are those that are divisible by 4, except the years that are divisible by...
-
For this lab, you will write a program to determine how many licks it takes to get to the chewy center of a Tootsie Pop. You will use both a while loop and a for loop to display how much of the outer...
-
Write a program that implements a cascade-form realization based on regular direct form II second-order modules.
-
Calculate the current bond yield for a bond that has a close of 108.633 and a coupon of 6.800%?
-
If Karp had used FIFO instead of LIFO, its reported net income for the year ended 31 December 2018 would have been higher by an amount closest to : A . \($30\) million. B . \($38\) million. C ....
-
For the linear part of the moisture absorption curve for a temperature of \(77^{\circ} \mathrm{C}\) in Figure 5.12, and assuming a specimen thickness of \(2.54 \mathrm{~mm}\), use the relevant...
-
Summerdahl Resorts common stock is currently trading at $36 a share. The stock is expected to pay a dividend of $3.00 a share at the end of the year (D1 = $3.00), and the dividend is expected to grow...
-
Some managers argue that international joint ventures/alliances are more costly than beneficial in terms of problems, making these ventures almost doomed to failure before beginning. Do you agree...
-
You plan to open a small business for manufacturing pet collars, leashes, and harnesses. You have found a workshop space you can use for sewing your products. After some research and planning, you...
-
Write the following expression as a single summation in terms of k. k = 1 k k + 2 ? m + 1 + == m+3 k = 1
-
On March 1, ABC Holdings purchased land and three buildings for $1,200,000. The plan was to use "Building 1" as an office and to demolish "Building 2" and "Building 3" to make room for a parking lot....
-
For the equation 2x+14=-2, x equals
-
Draw and label all the forces acting on the barbell, which is at rest in Arnold's hands. If the barbell weighs 5 0 kg and each weight on the bar weighs 2 5 kg , how much force must each arm be...
-
Acting as an accounting advisor to the firm, prepare a memo in which you analyze the financial statements prepared in step two and three and along with the ratios that have been calculated above and...
-
Complete the following table. Note that m is a non-zero constant. Function Most general Antiderivative 1 2 3 4 5 7 Function 8 K, (a constant) (ax+b)", n-1 (ax+b). e = 1 (ax+b) 6 cot (ax+b)csc (ax+b)...
-
A 0.47-kg object connected to a light spring with a force constant of 21.4 N/m oscillates on a frictionless horizontal surface. The spring is compressed 4.0 cm and released from rest. (a) Determine...
-
Kims Konstructions has assembled the following data for a proposed straw-reinforced brick maker (SRBM): SRBM Cost: $26,000 Life: 5 years Revenue (p.a.) $11,000 Operating Expenses (p.a.) $3,000...
-
A digital communication link carries binary-coded words representing samples of an input signal xa(t) = 3 cos 600t + 2 cos 1800. The link is operated at 10,000 bits/s and each input sample is...
-
By trail-and-error design a third-order low pass filter with cutoff frequency at 0 = /9 radians/sample interval. Start your search with (a) z1 = z2 = z3 = 0, p1 = r, p2.3 = rejk, r = 0.8 (b) r = 0.9,...
-
A causal pole-zero system is BIBO stable if its poles are inside the unit circle. Consider now a pole-zero system that is BIBO stable and has its poles inside the unit circle. Is the system always...
-
Using the transformation \(w=\sin (z)\), determine the equation for the stream function for flow inside the semi-infinite region \(y \geq 0,-\pi / 2 \leq x \leq \pi / 2\) shown in Figure P9.17. -/2...
-
The method of images uses precisely oriented collections of sources, sinks, and vortices to establish artificial walls and so simulate more complicated flow fields. One such flow field is formed by...
-
A stream function is given by: \[\psi=\sin \left(\frac{x}{L} ight) \sinh \left(\frac{y}{K} ight)\] where \(L\) and \(K\) are constants, \(0 \leq x \leq \pi L\) and \(y \geq 0\). a. Does \(\psi\)...
Study smarter with the SolutionInn App