Self-Referential Structure सेल्फ रेफरेंशियल स्ट्रक्चर
If a structure defines one or more pointer variables of the same structure type as its data members, it is called a self-referential structure.
In other words, a self-referential structure contains a pointer member which can point to another structure variable of the same type.
यदि एक स्ट्रक्चर अपने डेटा मेंबर्स के रूप में उसी प्रकार के एक या अधिक पॉइंटर वेरिएबल्स रखता है, तो उसे सेल्फ रेफरेंशियल स्ट्रक्चर (Self-Referential Structure) कहा जाता है।
दूसरे शब्दों में, सेल्फ रेफरेंशियल स्ट्रक्चर में एक ऐसा पॉइंटर मेंबर होता है जो उसी प्रकार के किसी अन्य स्ट्रक्चर वेरिएबल को पॉइंट कर सकता है।
Syntax:
struct structure_name
{
data_type member1;
data_type member2;
struct structure_name *pointer_name;
};Example:
struct node
{
int info;
struct node *link;
};Explanation:
In the above example:
struct nodeis a structure type.infois an integer data member.linkis a pointer member of typestruct node *.linkcan store the address of another structure variable of typestruct node.
उपरोक्त उदाहरण में:
struct nodeएक स्ट्रक्चर टाइप है।infoएक इन्टिजर डेटा मेंबर है।linkएकstruct node *टाइप का पॉइंटर मेंबर है।linkउसी प्रकार के किसी अन्य स्ट्रक्चर वेरिएबलstruct nodeका एड्रेस स्टोर कर सकता है।
Important Note:
Self-referential structures are commonly used to create dynamic data structures such as:
Linked List
Stack
Queue
Tree
Graph
सेल्फ रेफरेंशियल स्ट्रक्चर का प्रयोग सामान्यतः डायनामिक डेटा स्ट्रक्चर बनाने के लिए किया जाता है, जैसे:
लिंक्ड लिस्ट
स्टैक
क्यू
ट्री
ग्राफ
Comments
Post a Comment