Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 0 1 5 ICS QUESTION pure comp sci extra Q , given extra Q than CSB . . . 4 . Question Four: In

2015 ICS QUESTION pure comp sci extra Q , given extra Q than CSB ...
4. Question Four:
In a normal singly-linked list, there is a pointer in each element of the list that
points to the next element:
Header A B c D
rndin | Joa}{ Tl [ Teo} N
tail |&D|
in a subtraction linked list, the next pointer instead contains a computed
value. This value is the address of the next element in the list minus the
address of the previous element:
Header A B C D
vesdsa | o Taw0][Jacea][Jevea][oac
tail |&D
The main advantage of a subtraction linked list is that it is possible to traverse
the list from either head to tail, or from tail to head. If one knows the address
of the previous element and the contents of the current element, it is always
possible to compute the address of the next element for forward traversal.
Similarly, if one knows the address of the next element and the contents of
the current element, it is always possible to compute the address of the
previous element; this allows the list to be traversed in reverse order from tail
to head.
Subtraction linked lists combine many of the advantages of singly- and
doubly-linked lists. Like a doubly-linked list, the list can be traversed in both
directions. Like a singly linked list, only one pointer value per element needs
to be stored.
Write an abstract data type (ADT) to represent lists of floating point numbers
that internally uses a subtraction linked list. Your ADT should provide
functions to perform each of the following operations:
struct list * list_new(); /I create new empty list
float list_sum(struct list * this); 11 return sum of values in list
float list_get(struct list * this, int n); 1 return value of n'th item in list
float list_val_end(struct list * this, int n); 1 return n'th value from end of list
void list_remove(struct list * this, float num); // remove all list elements == num
void list_insert(struct list * this, float val, int n); // insert value val to the list; new value
/Ishould inserted just before existing
/l item n in the list; if n==0, insert at start
1 of list
void list_free(struct list * this); 1/ free memory of existing list
Your ADT should be implemented using a subtraction list and not another
data structure. Your code should be written with appropriate comments,
indentation, meaningful names, and good style.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

Let Y 1 Answered: 1 week ago

Answered: 1 week ago