Struct in a struct
Is this usage suitable, and what does it mean?
struct Taken
{
int *p;
开发者_如何学Cstruct Taken *previous;
};
It's probably a linked list, but it's not a struct in a struct, it's a pointer to a struct.
struct Taken *previous;
This line declares previous
to be a pointer to another structure of the same type Taken
-- this can be used to chain together several such structures, for example, to form a linked list. If you're not familiar with this kind of usage, you should probably read up on pointers and their applications.
Yes, that is the typical data structure for a linked list. A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next/previous record in the sequence
http://en.wikipedia.org/wiki/Linked_list
Yes, it's a suitable usage and what you're looking at is most likely a node in some sort of linked list.
It means that previous
is a pointer to a Taken
struct. Yes, it is valid.
This is the standard element that is used in a linked list.
精彩评论