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% (6 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...
-
The telephone company offers a variety of services. A business research firm is hired to determine the level of customer satisfaction by target audience with its land-based telephone service, its...
-
Simulate the path of a Brownian motion over a year (using your favorite programming language or Excel) by simulating N standard normal random variables zi and calculating Bti = Bti1 +zi t for i =...
-
During its first year of operations, Eastern Data Links Corporation entered into the following transactions relating to shareholders' equity. The articles of incorporation authorized the issue of 8...
-
Consider the BS model with S0=120,=0.2,r=0.04,T=1 and =0.3. The price of a call option with strike price K=100 is
-
Jake Nguyen runs a nervous hand through his once finely combed hair. He loosens his once perfectly knotted silk tie. And he rubs his sweaty hands across his once immaculately pressed trousers. Today...
-
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...
-
Walla Walla Winery requested that you determine whether the company's ability to pay its current liabilities and long-term debts improved or deteriorated during 2016. To answer this question, compute...
-
Based on contract law principles, do you think the jury\'s verdict against the Loewen Group for $ 5 0 0 million was appropriate? Why or why not? What factors should the jury have considered in...
-
5.) Consider you have two systems - one filled with (1kg) water and the other with (1kg) of air. Both systems are at 1000 kPa and 30 C. Determine numerically which fluid system has the larger...
-
Question 3: The partnership of Blossom, Blue, and Kingbird engaged you to adjust its accounting records and convert them uniformly to the accrual basis in anticipation of admitting Kerns as a new...
-
Instructions : Build an Excel spreadsheet using the accounting equation (Assets = Liabilities + Shareholders' Equity). Remember that each transaction has an equal effect on both the left-hand side...
-
7.3 Fill in the spreadsheet below to calculate the port- folio return and risk between Zenon and Dynamics, given the 10 years of annual returns for each stock and portfolio weights of 50/50. (a) How...
-
Define budget deficit. Historically, when has the federal government been most likely to run deficits? What has been the recent experience?
-
Suppose the government bond described in problem 1 above is held for five years and then the savings institution acquiring the bond decides to sell it at a price of $940. Can you figure out the...
-
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?
-
When credit terms for a sale are 2/15, n/40, the customer saves by paying early. What percent (rounded) would this savings amount to on an annual basis
-
An industrial robot that is depreciated by the MACRS method has B = $60,000 and a 5-year depreciable life. If the depreciation charge in year 3 is $8,640, the salvage value that was used in the...
-
What determines a firm's beta? Should firm management make changes to its beta? Be sure to consider the implications for the firm's investors using CAPM.
Study smarter with the SolutionInn App