For this question, you need to write a program that implements a doubly-like linked structure. Your...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For this question, you need to write a program that implements a doubly-like linked structure. Your code should be able to create such a structure and add objects (of generic type E) to this structure. Each node in the list is an instance of a (nested) Node class (see attached code). Each instance of Node points to two other Node instances: the node immediately to its right (next) and the node before it by skipping one (prevSkip)! (see examples below for prevSkip illustration) A single node in this structure will look like this: For simplicity, the node will be drawn as: prevSkip next prevSkip 5 next Once the node point to a null, the typical symbol used in lectures will be used This class has a main function called add. Once the add function is used repeatedly for the following four integer objects: 5,2,7,3 starting from an empty list, the result after each add is: Head prevSkip 5 next next 2 Head prevSkip 5 Head prevskip prevskip next next next 5 2 7 Head 5 prevskip Prevskip 3 Moreover, your code should be able to transform a given one-dimensional array of objects (of a generic type E) into this structure. This can be done at the construction time (using a specific constructor). Example: Integer [6] As an array: 5 2 7 3 1 9 As a doubly-like linked structure: Head 5 2 7 3 9 Question 1 is decomposed into five sub-questions: Questions 1.1 to 1.5. The implementation of all these questions will all be done in Linked DoublySkip.java (The only file to be uploaded back). Questions: 1.1) public void add(E object) { .... //8 marks 1.2) 1.3) This is a public function that adds one extra node to the structure. public LinkedDoublySkip() { ... //2 marks This is the default constructor. public Linked DoublySkip(E[] array) { .... //5 marks This constructor receives an array and creates a list structure from the array content. Hint: you can call other methods from the same class (e.g. add(...)). 1.4) public E getElementAt(int index) { .... //6 marks 1.5) This function returns the element at position index, assuming the first node in the list is at position 0 private class Linked Doublylterator implements Iterator {... //9 marks Finish the constructor Linked DoublyIterator and methods hasNext and next and add any necessary private variables (if needed!) to iterate the structure as shown in the sample output (once you reach the last node, follow prevSkip to the first node). Sample test class: (See Q1Test.java file) Sample output: List 1 with toString List 2 with toString List 1 with getElementAt List 2 with getElementAt List 1 with iIterator List 2 with iIterator 1, 2, 3, 4 1, 2, 3, 4, 5 1, 2, 3, 4 1, 2, 3, 4, 5 1, 2, 3, 4, 2, 1 1, 2, 3, 4, 5, 3, 1 -- second set of test cases: using the second constructor List 1 with toString List 2 with toString List 1 with getElementAt List 2 with getElementAt List 1 with iIterator List 2 with iIterator : 5, 2, 7, 3, 1, 9 : 5, 2, 7, 3, 1, 9, 10 : 5, 2, 7, 3, 1, 9 : 5, 2, 7, 3, 1, 9, 10 : 5, 2, 7, 3, 1, 9, : 5, 2, 7, 3, 1, 9, Important Restrictions for Question 1 -- 3, 2, 5 10, 1, 7, 5 You cannot define any new variable or method in the classes Linked DoublySkip or Node You may define new private variables in the inner class Linked DoublyIterator. Do not add any exception handling beyond what is provided to you in the shell implementation. . You cannot import anything at all. You cannot use any other classes than the ones we provide. The file LinkedDoublySkip.java should contain all your answers to all five questions. For this question, you need to write a program that implements a doubly-like linked structure. Your code should be able to create such a structure and add objects (of generic type E) to this structure. Each node in the list is an instance of a (nested) Node class (see attached code). Each instance of Node points to two other Node instances: the node immediately to its right (next) and the node before it by skipping one (prevSkip)! (see examples below for prevSkip illustration) A single node in this structure will look like this: For simplicity, the node will be drawn as: prevSkip next prevSkip 5 next Once the node point to a null, the typical symbol used in lectures will be used This class has a main function called add. Once the add function is used repeatedly for the following four integer objects: 5,2,7,3 starting from an empty list, the result after each add is: Head prevSkip 5 next next 2 Head prevSkip 5 Head prevskip prevskip next next next 5 2 7 Head 5 prevskip Prevskip 3 Moreover, your code should be able to transform a given one-dimensional array of objects (of a generic type E) into this structure. This can be done at the construction time (using a specific constructor). Example: Integer [6] As an array: 5 2 7 3 1 9 As a doubly-like linked structure: Head 5 2 7 3 9 Question 1 is decomposed into five sub-questions: Questions 1.1 to 1.5. The implementation of all these questions will all be done in Linked DoublySkip.java (The only file to be uploaded back). Questions: 1.1) public void add(E object) { .... //8 marks 1.2) 1.3) This is a public function that adds one extra node to the structure. public LinkedDoublySkip() { ... //2 marks This is the default constructor. public Linked DoublySkip(E[] array) { .... //5 marks This constructor receives an array and creates a list structure from the array content. Hint: you can call other methods from the same class (e.g. add(...)). 1.4) public E getElementAt(int index) { .... //6 marks 1.5) This function returns the element at position index, assuming the first node in the list is at position 0 private class Linked Doublylterator implements Iterator {... //9 marks Finish the constructor Linked DoublyIterator and methods hasNext and next and add any necessary private variables (if needed!) to iterate the structure as shown in the sample output (once you reach the last node, follow prevSkip to the first node). Sample test class: (See Q1Test.java file) Sample output: List 1 with toString List 2 with toString List 1 with getElementAt List 2 with getElementAt List 1 with iIterator List 2 with iIterator 1, 2, 3, 4 1, 2, 3, 4, 5 1, 2, 3, 4 1, 2, 3, 4, 5 1, 2, 3, 4, 2, 1 1, 2, 3, 4, 5, 3, 1 -- second set of test cases: using the second constructor List 1 with toString List 2 with toString List 1 with getElementAt List 2 with getElementAt List 1 with iIterator List 2 with iIterator : 5, 2, 7, 3, 1, 9 : 5, 2, 7, 3, 1, 9, 10 : 5, 2, 7, 3, 1, 9 : 5, 2, 7, 3, 1, 9, 10 : 5, 2, 7, 3, 1, 9, : 5, 2, 7, 3, 1, 9, Important Restrictions for Question 1 -- 3, 2, 5 10, 1, 7, 5 You cannot define any new variable or method in the classes Linked DoublySkip or Node You may define new private variables in the inner class Linked DoublyIterator. Do not add any exception handling beyond what is provided to you in the shell implementation. . You cannot import anything at all. You cannot use any other classes than the ones we provide. The file LinkedDoublySkip.java should contain all your answers to all five questions.
Expert Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Microkernel operating systems aim to address perceived modularity and reliability issues in traditional "monolithic" operating systems. (i) Describe the typical architecture of a microkernel...
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
Q1. a)Analyse Spencers experience in terms of consumer behavior framework in your notes. What variables and processes can you identify that appear to work in this situation? Does this situation...
-
Six criteria must all be satisfied for an expenditure to qualify as a development cost and be eligible for capitalization. Required: Identify each of the six criteria and explain why each one is...
-
Determine the present equivalent value of the cash-flow diagram of Figure P4-97 when the annual interest rate, it, varies as indicated $2.000 2.000 $1,000 $1,000 6 Years
-
The wood column is pinned at its base and top. If \(L=5 \mathrm{ft}\), determine the maximum eccentric load \(P\) that can be applied without causing the column to buckle or yield....
-
1. List possible objects in the library operation, including their attributes and methods. 2. Identify possible use cases and actors. 3. Select one of the use cases and create a sequence diagram. 4....
-
A machine costing $207,800 with a four-year life and an estimated $17,000 salvage value is installed in Luther Company's factory on January 1. The factory manager estimates the machine will produce...
-
Explain how the knowledge that you have gained so far in this course helps you to understand the SECs 2003 interpretation. Summarize how your knowledge would help you if you worked for a financial...
-
17-x, 2 for x 0 Let f(x) = Find each limit. 17+x, for x>0 (A) lim f(x) (B) lim f(x) x-0 (C) lim f(x) x-0 (D) f(0)
-
The technical support call centre for a software company has a mean wait time of 210 s, with a standard deviation of 40 s. The management team wants to continue to improve customer satisfaction by...
-
1/ You have two different assets (investments). Asset A (perpetuity) will pay you $1,000 in one year, $1,000 in two years, $1,000 in three years, and so on every year forever. Asset B will pay you...
-
A space for storing boxes is 36 inches high. Each box is 6 inches high. A space of 9 inches must be left at the top.
-
2. The benefits of financial planning Aa Aa Why Engage in Personal Financial Planning? Many people mistakenly believe that personal financial planning is an activity appropriate for only the wealthy;...
-
We are interested in the impact of an exercise program on weight. Below is the Excel output from a study to see whether there is evidence of a difference in the mean weight between those in the...
-
In the current year, the City of Omaha donates land worth $500,000 to Ace Corporation to induce it to locate in Omaha and create an estimated 2,000 jobs for its citizens. a. How much income, if any,...
-
A multiple-leaf spring used in automobiles is shown in Fig. 12.17. It consists of five leaves, each of thickness \(t=0.65 \mathrm{~cm}\) and width \(w=3.8 \mathrm{~cm}\). For the multiple-leaf spring...
-
Fill in the Blank. For a thin beam element, __________ degrees of freedom are considered at each node.
-
True or False. The Rayleigh-Ritz method assumes that the solution is a series of functions that satisfy the boundary conditions of the problem.
Study smarter with the SolutionInn App