A circular linked list is one in which the next field for the last link node of
Question:
A circular linked list is one in which the next field for the last link node of the list points to the first link node of the list. This can be useful when you wish to have a relative positioning for elements, but no concept of an absolute first or last position.
(a) Modify the code of Figure 4.8 to implement circular singly linked lists.
(b) Modify the code of Figure 4.14 to implement circular doubly linked lists.
Transcribed Image Text:
// Linked list implementation class LList implements List { private Link head; private Link tail; protected Link curr; int cnt; //Constructors // Constructor LList (int size) { this(); } LList() { Ignore size curr = tail = head = new Link (null); // Create header cnt = 0; } public void clear() { // Remove all elements // Drop access to links head.setNext (null); curr = tail = head = new Link (null); // Create header cnt = 0; } } // Insert "it" at current position public void insert (E it) { curr.setNext (new Link (it, curr.next())); if (tail == curr) tail = curr.next(); // New tail cnt++; // Pointer to list header // Pointer to last element // Access to current element // Size of list } public void append (E it) { // Append "it" to list tail = tail.setNext (new Link (it, null)); cnt++; public void moveToStart() {curr = head; } } -- // Remove and return current element public E remove () { if (curr.next() == null) return null; E it = curr.next().element (); if (tail == curr.next()) tail = curr; curr.setNext (curr.next() .next()); cnt--; return it; // Set curr at list start // Nothing to remove // Remember value // Removed last // Remove from list // Decrement count. // Return value Figure 4.8 A linked list implementation.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 0% (2 reviews)
To modify the code in Figure 48 to implement a circular singly linked list ...View the full answer
Answered By
Shadrack Mulunga
I am a Biochemistry by profession. However, I have explored different fields of study. My quest to explore new fields has helped me gain new knowledge and skills in Business, clinical psychology, sociology, organizational behavior and general management, and Project Management. I count my expertise in Project management, in particular, creation of Work Break Down Structure (WBS) and use of Microsoft Project software as one of my greatest achievement in Freelancing industry. I have helped thousands of BSC and MSC students to complete their projects on time and cost-effectively using the MS Project tool. Generally, I find happiness in translating my knowledge and expertise to success of my clients. So far, i have helped thousands of students to not only complete their projects in time but also receive high grades in their respective courses. Quality and timely delivery are the two key aspects that define my work. All those who hired my services always come back for my service. If you hire my services today, you will surely return for more. Try me today!
5.00+
154+ Reviews
289+ Question Solved
Related Book For
Practical Introduction To Data Structures And Algorithm Analysis Java Edition
ISBN: 9780136609117
1st Edition
Authors: Clifford A. Shaffer
Question Posted:
Students also viewed these Computer science questions
-
This role play will be about an interview with the client mentioned in the case scenario. Word limit will be around 500 words. Please make sure to cover the following points. In your role playas, you...
-
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...
-
In this chapter, we gave a linked list implementation of a queue. This implementation used two references, called front and rear, to refer to the front and the rear nodes of the queue (linked list)....
-
Read the Speech of Martin Luther King, Jr.'s "I Have a Dream" and answer the question: Kin, makes liberal use of metaphorand metaphorical imagery in his speech. (Glossary: Figures of Speech) Choose a...
-
A stream of ammonia enters a steady flow device at 100 kPa, 50C, at the rate of 1 kg/s. Two streams exit the device at equal mass flow rates; one is at 200 kPa, 50C, and the other as...
-
Nuts and bolts are perfect complements; a nut is valuable only when paired with a bolt, and vice versa. Ted spends all his money on nuts and bolts. On a graph, illustrate the effect of a compensated...
-
1 4 Appreciate the importance of financial results in evaluating performance
-
The ledger of Armour Lake Lumber Supply on July 31, 2019, includes the selected accounts below before adjusting entries have been prepared. An analysis of the company's accounts shows the following....
-
Porter, Inc., acquired a machine that cost $361,000 on October 1, 2016. The machine is expected to have a five-year useful life and an estimated salvage value of $32,000 at the end of its life....
-
Section 4.1 .3 states the space required by the array-based list implementation is (n), but can be greater. Explain why this is so.
-
Write a function to merge two linked lists. The input lists have their elements in sorted order, from smallest to highest. The output list should also be sorted from highest to lowest. Your algorithm...
-
The random variable x represents the number of phone calls the author receives in a day, and it has a Poisson distribution with a mean of 7.2 calls. What are the possible values of x? Is a value of x...
-
Leslie Sporting Goods is a locally owned store that specializes in printing team jerseys. The majority of its business comes from orders for various local teams and organizations. While Leslie's...
-
Euclid acquires a 7-year class asset on May 9, 2022, for $153,000 (the only asset acquired during the year). Euclid does not elect immediate expensing under 179. He does not claim any available...
-
Williams & Sons last year reported sales of $10 million, cost of goods sold (COGS) of $8 million, and an inventory turnover ratio of 2. The company is now adopting a new inventory system. If the new...
-
A ceramic manufacturer promised to deliver 25 crates of vases to a Japanese importer under a "CFR" INTERCOM agreement. During transit, however, a large number of vases were broken. The buyer wants to...
-
A company receives $364, of which $23 is for sales tax. The journal entry to record the sale would include a ?
-
The radiator of a steam heating system has a volume of 20 L and is filled with superheated water vapor at 200 kPa and 200C. At this moment both the inlet and the exit valves to the radiator are...
-
Using a graphing utility, graph y = cot -1 x.
-
A signal with 200 milliwatts power passes through 10 devices, each with an average noise of 2 microwatts. What is the SNR? What is the SNRdB?
-
A computer monitor has a resolution of 1200 by 1000 pixels. If each pixel uses 1024 colors, how many bits are needed to send the complete contents of a screen?
-
A file contains 2 million bytes. How long does it take to download this file using a 56-Kbps channel? 1-Mbps channel?
-
On April 1, year 1, Mary borrowed $200,000 to refinance the original mortgage on her principal residence. Mary paid 3 points to reduce her interest rate from 6 percent to 5 percent. The loan is for a...
-
Give a numerical example of: A) Current liabilities. B) Long-term liabilities?
-
Question Wonder Works Pte Ltd ( ' WW ' ) produces ceramic hair curlers to sell to department stores. The production equipment costs WW $ 7 0 , 0 0 0 four years ago. Currently, the net book value...
Study smarter with the SolutionInn App