Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 0 1 5 ICS QUESTION pure comp sci extra Q , given extra Q than CSB . . . 4 . Question Four: In
ICS QUESTION pure comp sci extra Q given extra Q than CSB
Question Four:
In a normal singlylinked 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 TawJaceaJeveaoac
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
doublylinked lists. Like a doublylinked 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 listnew; I create new empty list
float listsumstruct list this; return sum of values in list
float listgetstruct list this, int n; return value of nth item in list
float listvalendstruct list this, int n; return nth value from end of list
void listremovestruct list this, float num; remove all list elements num
void listinsertstruct 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 insert at start
of list
void listfreestruct list this; 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started