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...
-
Solve for V 1 in the circuit of Fig. 3.55 using nodal analysis. 10 2 20 V 10 V V, 102 +,
-
Refer to the information in Problem 21-1B. Tohono Companys actual income statement for 2017 follows. Required 1. Prepare a flexible budget performance report for 2017. Analysis Component 2. Analyze...
-
Samuel Aldrich started his own delivery service, Aldrich Service Inc., on June 1, 2012. The following transactions occurred during the month of June. June 1 Stockholders invested $15,000 cash in the...
-
Shelby Woods owns and operates an ice cream factory, the finest of its kind in all the world. Given that pints of ice cream are meant to be identical (for the same flavor), her company uses process...
-
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...
-
If you take samples of 40 lines from a random number table and find that the confidence interval for the proportion of odd-numbered digits captures 50% 37 times out of the 40 lines, is it the...
-
Phillips Curve: = E 0.5(u 6) Expected inflation: E = 0.71 + 0.32 Okun's Law: (Y Y1)/Y1 = 3.0 2.0(ut ut1) Create a table showing unemployment, inflation, expected inflation, and output growth for 10...
-
3) Find the moment of inertia of a hollow cylinder with mass m, length L. The object is rotating around its axis of symmetry. The distance from the axis to the inner edge of the shell is a, and the...
-
Why should you puree or pulverize the shells and aromatic vegetables?
-
Two ions are accelerated from rest in a mass spectrometer operating with potential difference AV. The first ion, with mass m, is singly ionized and is deflected into a semicircle of radius R by the...
-
When a constant force is applied to an object, the acceleration of the object varies inversely with its mass. When a certain constant force acts upon an object with mass 11 kg, the acceleration of...
-
Square Manufacturing is considering investing in a robotics manufacturing line. Installation of the line will cost an estimated $4.5 million. This amount must be paid immediately even though...
-
The figure shows six containers, each of which is filled from the top. Assume that water is poured into the containers at a constant rate and each container is filled in 10 seconds. Assume also that...
-
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?
-
Supply the missing data for three service companies shown in the table below: Note: Loss amounts should be indicated by a minus sign. Round your percentage answers to nearest whole percent. Sales Net...
-
As a safety practitioner or professional, you should assist, support, and guide those who do not fully understand how to demonstrate safety leadership, but organizational leaders who are already...
-
If you have questions regarding the course materials, technical problems, or if you are struggling with the course you contact either the Instructor or the Technical Support Desk (whichever is...
Study smarter with the SolutionInn App