Linked List Representation in C
In C, a linked list is represented using a node structure and one or more pointers (usually head, sometimes tail). This design gives dynamic memory usage and easy pointer-based linking between nodes.
1) Node structure in C
data and next.struct Node {
int data;
struct Node *next;
};
struct Node *head = NULL; // empty list
struct Node *tail = NULL; // optional, for faster end insert
datastores the value for the node.nextstores the address of the next node.headpoints to the first node; when list is empty,head == NULL.
2) What is UDD? (User-Defined Data type)
In C, a User-Defined Data type (UDD) is a type you create, instead of using only built-in types like int, char, or float. struct Node is a UDD because we define its fields ourselves.
typedef struct Node {
int data;
struct Node *next;
} Node;
Node *head = NULL;
Using UDD makes linked-list code cleaner and reusable: every function can work with the same logical node type.
3) What is a self-referential structure?
A self-referential structure is a structure that contains a pointer to the same structure type. In linked lists, this is the key idea that creates a chain of nodes.
struct Node *next;means each node can point to anotherNode.- Without this self-reference, nodes cannot be linked dynamically.
- This pattern is also used in trees and graph node representations.
4) Why is structure used for linked list?
- Group related fields: data and link(s) stay together as one node record.
- Dynamic memory-friendly: each node is allocated when needed using
malloc(). - Flexible node design: you can add more fields (e.g., id, name, marks, timestamp) without changing list logic.
- Pointer-based linking: structures can safely hold pointer members like
nextandprev. - Readable code: operations like insert/delete/traverse become clear via
node->nextstyle access.