Implement doubly linked lists by storing the sum of the next and prev pointers in a single
Question:
Implement doubly linked lists by storing the sum of the next and prev pointers in a single pointer variable as described in Example 4.1.
Transcribed Image Text:
Example 4.1 There is a space-saving technique that can be employed to eliminate the additional space requirement, though it will complicate the implementation and be somewhat slower. Thus, the technique is an example of a space/time tradeoff. It is based on observing that, if we store the sum of two values, then we can get either value back by subtracting the other. That is, if we store a + b in variable c, then b = ca and a = c - b. Of course, to recover one of the values out of the stored summation, the other value must be supplied. A pointer to the first node in the list, along with the value of one of its two link fields, will allow access to all of the remaining nodes of the list in order. This is because the pointer to the node must be the same as the value of the following node's prev pointer, as well as the previous node's next pointer. It is possible to move down the list breaking apart the summed link fields as though you were opening a zipper. Details for implementing this variation are left as an exercise. The principle behind this technique is worth remembering, because it has many applications. The following code fragment will swap the contents of two variables without using a temporary variable (at the cost of three arithmetic operations). a = a + b; b = = a a = a - - b; // Now b contains original value of a b; // Now a contains original value of b
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 50% (2 reviews)
The technique described here is a classic example of a spacetime tradeoff Its based on the observati...View the full answer
Answered By
S Mwaura
A quality-driven writer with special technical skills and vast experience in various disciplines. A plagiarism-free paper and impeccable quality content are what I deliver. Timely delivery and originality are guaranteed. Kindly allow me to do any work for you and I guarantee you an A-worthy paper.
4.80+
27+ Reviews
73+ 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
-
When using the list class of Example 10.17, the typical C++ programmer will use a pointer type for generic parameter V, so that list_nodes point to the elements of the list. An alternative...
-
Explain how to implement doubly linked lists using only one pointer value x.np per item instead of the usual two (next and prev). Assume that all pointer values can be interpreted as k-bit integers,...
-
Determine whether the underlined number describes a population parameter or a sample statistic. Explain your reasoning. Sixty - five of the 93 passengers aboard an airship survived an explosion....
-
Discuss the various ways project change can be managed. In your discussion, be sure to include real world examples if you have experienced them those experiences may help your project
-
A small pump is driven by a 2 kW motor with liquid water at 150 kPa, 10C entering. Find the maximum water flow rate you can get with an exit pressure of 1 MPa and negligible kinetic energies....
-
Calculate the area of a piece of property bounded by a traverse and circular arc with the following coordinates in feet at angle points: A (526.68, 823.98), B (535.17, 745.61), C (745.17, 745.61), D...
-
1 How does the company compare on these measures against M&S?
-
Warner Co. entered into the following transactions involving short-term liabilities in 2016 and 2017. 2016 Apr. 22 Purchased $5,000 of merchandise on credit from Fox-Pro, terms n30. Warner uses the...
-
Your credit card company charges you 1.23 percent per month. What is the EAR on your credit card? A. 15.80% B. 15.28% C. 14.76% D. 16.59% E. 14.02%
-
Implement a city database using unordered lists. Each database record contains the name of the city (a string of arbitrary length) and the coordinates of the city expressed as integer x and y...
-
Use singly linked lists to implement integers of unlimited size. Each node of the list should store one digit of the integer. You should implement addition, subtraction, multiplication, and...
-
In 30 words or fewer, explain the difference between a sales discount and a purchase discount.
-
Could I obtain assistance with these . problems? 1. Find the coordinates of the turning points of the curve y=3x^4-8x^3-30x^2+72x+5. Determine the nature of these points. "Determine the nature"...
-
1 . In 1 9 6 0 the homeownership rate in the United States was 6 2 % . Is there evidence to indicate that the homeownership rate is now higher? To answer the question, the researchers sample 5 0 2...
-
A certain disease is classified into 4 stages that distinguish how developed the disease is. Researchers studying a new potential treatment recruited over 100 patients with varying stages of the...
-
1. (20) Let and Dor {abnm or 2n m} = Dand = {a"b" nm and 2n m}. Prove that Dor and Dand are both context-free.
-
Given n samples 1 , 2 , . . . , x 1 ,x 2 ,...,x N drawn independently from a Poisson distribution unknown parameter , find the MLE of . = = 1 MLE = i=1 n x i = = 1 MLE =n i=1 n x i = = 1 MLE = i=1 n...
-
A piston - cylinder device initially contains 1.4 kg of refrigerant-134a at 100 kPa and 20C. Heat is now transferred to the refrigerant from a source at 150C, and the piston which is resting on a set...
-
Write an SQL statement to display all data on products having a QuantityOnHand greater than 0.
-
Which of the three analog-to-analog conversion techniques (AM, FM, or PM) is the most susceptible to noise? Defend your answer.
-
A corporation has a medium with a 1-MHz bandwidth (lowpass). The corporation needs to create 10 separate independent channels each capable of sending at least 10 Mbps. The company has decided to use...
-
Which characteristics of an analog signal are changed to represent the lowpass analog signal in each of the following analog-to-analog conversions? a. AM b. FM c. PM
-
1-The yield to maturity will be greater than the coupon rate when a bond is selling at a premium. Select one: a. False b. True 2-Which one of the following would have the greatest present value,...
-
! Required information [ The following information applies to the questions displayed below. ] Year 1 total cash dividends Year 2 total cash dividends Year 3 total cash dividends Year 4 total cash...
-
WISE-HOLLAND CORPORATION On June 15, 2013, Marianne Wise and Dory Holland came to your office for an initial meeting. The primary purpose of the meeting was to discuss Wise-Holland Corporation's tax...
Study smarter with the SolutionInn App