Question 39 Which type of linked list does the below given code snippet represent?
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Question 39
Which type of linked list does the below given code snippet represent?
struct node {
int data;
struct node *next;
struct node *prev;
}
Show answer & explanation
Answer: A. Doubly linked list
The struct defines a node with three components: data, a next pointer, and a prev pointer. The presence of both next and prev pointers is the defining characteristic of a doubly linked list, which allows traversal in both directions. The struct itself does not enforce circularity (where the last node points back to the first); circularity is a property of how nodes are linked at runtime, not the struct definition.
Step-by-step Derivation:
Analysis of the node structure:
- The struct contains: int data, struct node *next, struct node *prev
- A single forward pointer (next) defines a singly linked list
- A single backward pointer (prev) alone would be unusual
- Both next AND prev pointers together define a doubly linked list — each node can reference both its successor and predecessor
- Circular vs. non-circular is determined by runtime linking logic (e.g., whether last.next points to first and first.prev points to last), not by the struct definition
- The struct as written is the template for a doubly linked list node, regardless of whether instances are arranged circularly