Presentation is loading. Please wait.

Presentation is loading. Please wait.

Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };

Similar presentations


Presentation on theme: "Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };"— Presentation transcript:

1 Self Referential Structure

2 A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };

3 Self Referential Structure However, a structure may contain a pointer of same type. They allow you to create data structures that contains references to data of the same type as themselves. This type of structure, called self referential structure struct check { int a; struct check *p; // Valid };

4 Self Referential Structure Self-referential Structure is used in data structure such as linked list, Binary tree, stack, Queue etc.

5 Self Referential Structure Linked List Method of organizing stored data in a computedata Collection of Nodes Each Nodes contains 2 parts Information Part and Link Part Information Part contains actual data Link part(address Part) contains address of next Node Linked-Lists are useful because, can insert or delete Nodes very easily. Unlike arrays, there are no issues of reallocating memory and copying data. It is Dynamic Memory allocation( Run time) Data Address

6 Self Referential Structure Linked List The last node address will be ‘Null’ By Interchanging of links(Address) part, can easily insert or delete a node at run time Eg: Inserting a node Data Address Data Address Data NULL

7 Self Referential Structure Example to creating Linked List struct list { int data; struct list *link; }; struct list node; Node  variable of type struct list, contains node.data (actual data) and node.link (address of next node of same type)


Download ppt "Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };"

Similar presentations


Ads by Google