1. What does the following function do for a given Linked Listst with first node
ID: 3919872 • Letter: 1
Question
1. What does the following function do for a given Linked Listst with first node as head?
a. Prints all nodes of linked lists.
b. Prints all nodes of linked list in reverse order.
c. Prints alternate nodes of Linked Lists.
d. Prints alternate nodes in reverse order.
2. In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is:
a. log2n. b. n/2. c. log2n-1. d. n
3. Point out the error in the following C code?
struct emp {
int ecode;
4. What does the following fragment of code do with a linked list?
a) It initializes the list
b) It counts the number of items in the list c) Ittraversesthelist
d) None of them
Explanation / Answer
1. b. Prints all nodes of linked list in reverse order.
Explanation: Because it is recursively called first and then printed.
2. d. n
Explanation: Because there are n numbers and we need to search all of them
3. error: field 'e' has incomplete type 'emp'
struct emp e;
Correct code is to have: struct emp *e;
4. c) It traverses the list
Explanation: It neither printing nor initializing, it is just traversing from head till end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.