Q2) Assume that you are inside a Singly Linked List class. which means you have
ID: 3916173 • Letter: Q
Question
Q2) Assume that you are inside a Singly Linked List class. which means you have access to head and tail references. Assume also that the Node of singly linked list has info and next fields. Then write a Boolean expression (e.g. head--null) to test for each of the following conditions: a) The list has only one node. b) A node referenced by a variable tmp is the second in the list. c) A node referenced by a variable tmp is the second last (just before the last) in the list. d) A node referenced by a variable tmp is neither the first nor the last in the list.Explanation / Answer
a. List has only one node: That node should not be null and head and tail should be same.. (head != null) && (head == tail) b. (head != null) && (head->next == tmp) c. (tmp != null) && (tail != null) && (tmp->next == tail) d. (tmp != head) && (tmp != tail)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.