我想创建一个主列表,每个主列表元素都有另一个列表。
这是我做的
typedef struct smallList
{ char data;
struct smallList *next;
} small;
typedef struct bigList
{
int count;
char data;
struct bigList *next;
struct smallList *head;
} big;
但是我如何从大列表中访问小列表数据并将内容添加到小列表中。 非常感谢任何帮助。谢谢....
最佳答案
所以,如果我们假设这个结构已经被填充,我们可以这样做:
struct smallList *smallElem = NULL;
struct bigList *bigElem = NULL;
for (bigElem = your_big_list(); bigElem != NULL; bigElem = bigElem->next) {
// Do something with bigElem.
for (smallElem = bigElem->head; smallElem != NULL; smallElem = smallElem->next) {
// Do something with the smallElem.
// Note that we can still reference bigElem here as well.
}
}
关于c - 如何在c中的链表内创建链表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15144035/