Define the Self-Referential Structures?
It is occasionally desirable to include within a structure one member that is a pointer to the parent structure type. Generally in terms this can be expressed as
struct tag
{
member 1;
member 2;
. . . . .
struct tag *name;
} ;
Where name refers to the name of a pointer variable therefore the structure of type tag will contain a member that points to another structure of type tag. Such structures are called as self-referential structures.
A C program contains the following structure declaration.
struct list_element
{
char item[40];
struct list_element *nextj
} ;
This is a structure of type list_element and the structure encloses two members a 40-element character array, called item, and a pointer to a structure of the same type (that is a pointer to a structure of type list_element), called next. Thus this is a self-referential structure. .
The Self-referential structures are extremely useful in applications that involve linked data structures, such as trees and lists. The fundamental idea of a linked data structure is that each component within the structure includes a pointer indicating where the next component is able to be found. Consequently the relative order of the components can simply be changed simply by altering the pointers. As well individual components can easily be deleted or added again by altering the pointers. As a result, a linked data structure isn't confined to some maximum number of components. Somewhat the data structure can expand or contract in size as required.
Figure shown below exemplify a linked list containing three components. Every component consists of two data items a string, and a pointer that references the next component within the list. Therefore the first component contains the string "red" the second contains "green" and the third contains "blue". The start of the list is indicated by a separate pointer, which is labeled "start". As well, the end of the list is indicated by a special pointer called as "NULL".