简体   繁体   中英

Linked list node with pointer to struct in C

I am new to C programming. Familiarising muself with struct pointers and linekd lists. I came across concept of linked list node with pointer to struct.

typedef struct
{
   string name, surname;
   int matriculation_num;
}Student_typedef;

typedef struct
{
   Tstudent* student;
   Node_typedef* next;
} Node_typedef;

Can anyone tell me what exactly is the purpose of Node_typedef. Where are such implementations usefull ? Any useful link is much appreciated.

The two shown struct type definitions separate the stored data from the storing mechanism.

You can see that Student_typedef has only members which relate to information to store, but none relating to storing. The goal is to have a mechanism which can store a multitude of this data structure.

On the other hand Node_typedef does not contain any of the information to store, only a single pointer to the complete data. If the structure of the inforamtion to store would change (though still be reflected by the same type identifier Student_typedef ), then nothing about this storage mechanism would have to be changed.

Or to describe it from a different angle, two developers working on a student database would only have to agree that all the needed information for each student is inside Student_typedef . Then one developer could handle programming functions to enter or edit a given struct (based on a pointer to the struct provided by the storage), while the other developer could handle storage aspects, like adding a new struct to fill, deleting, optimising memory, etc.

Such methods of interface definition and abstraction of code parts are necessary for efficiently handling large projects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM