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.
-
Shown are three separate pairs of point charges. Assume the pairs interact only with each other. Rank the magnitudes of the force between the pairs from largest to smallest. +2q -4q +3q +2q -2q
-
Write an assertion for the bank database to ensure that the assets value for the Perryridge branch is equal to the sum of all the amounts lent by the Perryridge branch.
-
Consider the vector \(u\) that consists of 32 equally spaced samples of the function \(f(t) \approx \cos (4 \pi t)\) on the interval [0,1]. That is, \(u_{1}=f(0), u_{2}=\) \(f\left(\frac{1}{32}...
-
1. Depreciation expense accounts would likely be found in the a. General fund b. Capital projects fund c. Debt service fund d. Enterprise fund 2. The government-wide statements of a state government...
-
Recall the code below that moved each row up by one. Now, create matrix z that is equal to matrix x but with each column shifted one column to the right. x=magic(3) y=x % Move each row up by one...
-
1. The ura ring is a premium product that offers unique features and is priced higher than the competition. Identify the pricing strategy the company is using. Explain this strategy and discuss why...
-
Calculate the value of a bond with 100 face value, 5 years to maturity, coupon rate of 6% p.a. paid semi-annually, when the discount rate (expected rate of return on similar instruments) is: 8,8 %...
-
Your Brother Will Receive $500 A Month For The Next Eight (8) Years From An Insurance Settlement. The Interest Rate Is 6 Percent Per Year For The First Three (3) Years; And 8 Percent Per Year For The...
-
A company exchanged a delivery van with a cost of $150,000 and accumulated depreciation of $50,000 for a new delivery van with a fair market value of $120,000 and $5,000 in cash. What amount of gain...
-
Why a company with very high net profits can still be in cash flow problems? List and explain three main reasons using examples.
-
Suppose that the current market price of the bond in Problem 1 is 95. Calculate the resulting redemption yield. A corporate bond with exactly five years left to maturity pays interest at 8% on its...
-
Develop a shaping strategy. The change that may occur will entail changing some element of performancestructure, processes, technology, groups, or the task. The purpose of the strategy is to...
-
Could you discuss emerging trends and innovations in virtualization, such as server less computing and edge virtualization, and their impact on reshaping application deployment models, infrastructure...
-
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...
-
Explain the concept of a control variable and the assumption necessary for a control variable to be effective.
-
Explain the properties of the restricted least squares estimator. In particular, how do its bias and variance compare with those of the unrestricted, ordinary, least squares estimator?
-
Explain the issues that need to be considered when choosing a regression model.
Study smarter with the SolutionInn App