You cannot have recursion within a data structure:
struct foo {
int x;
foo y; // compiler error
};
This has to fail; there is no end point to the recursion. If a foo is member of a foo, then the member foo also requires a member foo, and so on to infinity...
If a structure needs to refer to another instance of itself, we can use a member pointer:
struct foo {
int x;
foo* y; // ok
};
A pointer works because all pointers are the same length regardless of the pointer's type (the type being referred to).
Using member pointers like this is fundamental to many data structures, such as linked lists:
struct node {
int data;
node* prev; // previous node in the sequence (may be NULL)
node* next; // next node in the sequence (may be NULL)
};
Chat with our AI personalities
Because a tree is a recursive data-structure. It's easier to write (and easier to understand) a recursive program for handling it.
types of data structure types of data structure
How do you amend a data structure?
difference between serch data structure and allocation data structure
in homogeneous data structure all the elements of same data types known as homogeneous data structure. example:- array