Self Referential Structures
A structure can have members which point to a structure variable of the same type.
These types of structures are called self referential structures and are widely used in
dynamic data structures like trees, linked list, etc.
The following is a definition of a self referential structure.
struct node
{
int data;
struct node *next;
};
Here, next is a pointer to a struct node variable.
It should be remembered that a pointer to a structure is similar to a pointer to any other
variable.
A self referential data structure is essentially a structure definition which includes at least
one member that is a pointer to the structure of its own kind.
Such self referential structures are very useful in applications that involve linked data
structures, such as lists and trees.
Unlike a static data structure such as array where the number of elements that can be
inserted in the array is limited by the size of the array, a self referential structure can
dynamically be expanded or contracted.
Operations like insertion or deletion of nodes in a self referential structure involve simple
and straight forward alteration of pointers.