struct node
{
int info;
struct node *llink;
struct node *rlink;
};
typedef node *nodep;
What does it mean to have a structure’s pointer inside that structure itself?
Please explain the above structure in detail.
P.S.
I am NOT talking about the trees logic. I am talking about the C struct and the pointer’s behaviour.
EDIT 1:
struct node *llink How does the memory gets allocated to this? This is a type which hasn’t yet come into existence?
A pointer is just a reference to a location in memory (“address”). In the case of a
node, a pointer to an instance of anodeis a reference to the location in memory where thatnodeinstance is stored.For your
structas defined, if you have an instance of anodethat resides in one memory location, it can point to two othernodeinstances that reside in their own memory locations (*llink,*rlink).Using a real-world tree as a metaphor, the
*llinkand*rlinkare pointers to left and right “branches” of a root node of a tree structure, respectively. Those pointers themselves may branch off into further and deeper left and right “subtrees”.Have a read of this introduction to binary trees.