Data Structures. The median of a list is an element who has the same number of predecessors and successors in the list,
Posted: Sun May 15, 2022 10:05 am
Data Structures.
The median of a list is an element who has the same number of
predecessors and successors in the list, within a difference of 1
(for example, if the list contains 8 elements then the 4th and 5th
element are both medians). If the list has an even number of
elements, it has two medians; if the list has an odd number of
elements, then it has a single median.
a. Consider a doubly linked list, whose links are called fore and
back. We designate the head and tail of the list by pointers head
and tail. Give code that returns a median of the list, by using
link-hopping only (no counting of nodes).
b. Same question for singly linked list: Give code that returns a
median of a single linked list whose link is called fore. We
designate the head of the list by pointer head and we limit
ourselves to using link-hopping only (no counting of nodes).
The median of a list is an element who has the same number of
predecessors and successors in the list, within a difference of 1
(for example, if the list contains 8 elements then the 4th and 5th
element are both medians). If the list has an even number of
elements, it has two medians; if the list has an odd number of
elements, then it has a single median.
a. Consider a doubly linked list, whose links are called fore and
back. We designate the head and tail of the list by pointers head
and tail. Give code that returns a median of the list, by using
link-hopping only (no counting of nodes).
b. Same question for singly linked list: Give code that returns a
median of a single linked list whose link is called fore. We
designate the head of the list by pointer head and we limit
ourselves to using link-hopping only (no counting of nodes).