我想创建一个主列表,每个主列表元素都有另一个列表。
这就是我所做的

    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.
    }
}

07-26 04:58