In a circular doubly-linked list, the previous reference of the first node points to the last node,
Question:
In a circular doubly-linked list, the previous reference of the first node points to the last node, and the next reference of the last node points to the first node. Change the doubly-linked list implementation of Worked Example 16.1 into a circular list. You should remove the last instance variable because you can reach the last element as first.previous.
Data from worked example 16.1.
Transcribed Image Text:
WORKED EXAMPLE 16.1 Implementing a Doubly-Linked List Problem Statement Provide two enhancements to the linked list implementation from Section 16.1 so that it is a doubly-linked list. In a doubly-linked list, each node has a reference to the node preceding it, so we will add an instance variable previous: class Mode { public Object data; public Mode next; public Node previous; } We will also add a reference to the last node, which speeds up adding and removing elements at the end of the list: public class Linked List ( private Mode first; private Mode last; } We need to revisit all methods of the Linked List and ListIterator classes to make sure that these instance variables are properly updated. We will also add methods to add, remove, and get the last element. } Changes in the Linked List Class In the constructor, we simply add an initialization of the last instance variable: public Linked List() { first = null; last = null;
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (2 reviews)
To update the given doublylinked list implementation into a circular doublylinked list we need to modify the Node and LinkedList classes and certain methods in each class to ensure that the first nodes previous reference points to the last node and the last nodes next reference points to the first node ...View the full answer
Answered By
PALASH JHANWAR
I am a Chartered Accountant with AIR 45 in CA - IPCC. I am a Merit Holder ( B.Com ). The following is my educational details.
PLEASE ACCESS MY RESUME FROM THE FOLLOWING LINK: https://drive.google.com/file/d/1hYR1uch-ff6MRC_cDB07K6VqY9kQ3SFL/view?usp=sharing
3.80+
3+ Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Java Programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
(i) Write down the linear program relaxation for the vertex cover problem and solve the linear program. [6 marks] (ii) Based on the solution of the linear program in (b)(i), derive an integer...
-
(a) Sets containing integers can be represented as int list values. Consider two such representations called unordered and ordered. In the former elements can appear in any order; in the latter...
-
PWX Inc. has the following information for its years ended June 30: Required: Calculate the accounts receivable turnover and average collection period for 20X3 and 20X2. Comment on the trend. What...
-
An Ocean Thermal Energy Conversion (OTEC) power plant built in Hawaii in 1987 was designed to operate between the temperature limits of 86F at the ocean surface and 41F at a depth of 2100 ft. About...
-
1. Interim reporting under FASB ASC Topic 270 guidelines refers to financial reporting: a On a monthly basis b On a quarterly basis c On a regular basis d For periods less than a year 2. A...
-
Describe the four types of data analytics.
-
The total wages and salaries earned by all employees of Cutler Manufacturing Company during the month of March, as shown in the labor cost summary and the schedule of fixed administrative and sales...
-
are mortgage rates likely to go up or down during the next 1 2 to 1 8 months
-
Isorait Co is a company which installs kitchens and bathrooms to customer specifications. It is planning to invest KShs. 4,000,000 in a new facility to convert vans and trucks into motorhomes. Each...
-
Modify the insertion sort algorithm of Special Topic 14.2 to sort a linked list. Data from special topic 14.2 Special Topic 14.2 Insertion Sort Insertion sort is another simple sorting algorithm. In...
-
A linked list class with an O(1) addLast method needs an efficient mechanism to get to the end of the list, for example by setting an instance variable to the last element. It is then possible to...
-
What financial statements are prepared for an Investment Trust Fund?
-
During the Great Recession, many news stories focused on a rising number of discouraged workers. The implication of many of these stories is that the unemployment situation was worse than indicated...
-
Cindy gains utility from consumption C and leisure L. The most leisure she can consume in any given week is 110 hours. Her utility function is U(C, L) = C L. This functional form implies that Cindys...
-
Explain the difference between \(\hat{\beta}_{1}\) and \(\beta_{1}\); between the residual \(\hat{u}_{i}\) and the regression error \(u_{i}\); and between the OLS predicted value \(\hat{Y}_{i}\) and...
-
Suppose the economys labor market is competitive and that labor demand can be written as w = 50 0.3E while labor supply can be written as w = 8 + 0.2E where E is the total amount of employment in...
-
A random sample of 200 20-year-old men is selected from a population and these men's height and weight are recorded. A regression of weight on height yields \[ \widehat{\text { Weight }}=-99.41+3.94...
-
Describe possible approaches to a systems development effort and the advantages and disadvantages of each approach.
-
C- Consider the following scenario:- A supermarket needs to develop the following software to encourage regular customers. For this, the customer needs to supply his/her residence address, telephone...
-
State whether each of the following is true or false. If false, explain why. a) Providing the same value for a foreign key in multiple rows causes the DBMS to report an error. b) Providing a...
-
What does it mean to process tasks asynchronously?
-
What is the key advantage of programming your apps for multicore systems?
-
Use the formula P = 1+ A nt 1 to determine the periodic deposit. Periodic Deposit Rate Time Financial Goal $? at the end of every six months 10% compounded semiannually 8 years $350,000 $7268.91...
-
Beta Rf 0.99 Beta 4.70% Rf 1.07 4.70% Equity Risk Premium 5.04% Equity Risk Premium 5.46% (= Beta * (E(RM) - Rf)) (= Beta * (E(RM) - Rf)) Required Rate of Return 9.74% Required Rate of Return 10.16%...
-
es Duo Corporation is evaluating a project with the following cash flows: Year Cash Flow 0 -$ 28,700 1 10,900 2 13,600 15,500 345 12,600 -9,100 The company uses a discount rate of 12 percent and a...
Study smarter with the SolutionInn App