c - 如何在c中的链表内创建链表

标签 c linked-list structure

我想创建一个主列表,每个主列表元素都有另一个列表。

这是我做的

    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/

相关文章:

c - 斐波那契数列和 c 的问题

c++ - 为什么我的打印函数不会显示链表的任一子节点中的元素?

html - 填充和边距不起作用

在 __GI____strdup() 中因 SIGSEGV 崩溃

android - 在 Android 上运行 C 程序

C - 按字符串排序链表

c++ - 尝试将前一个节点链接到要删除的节点后的节点时出错

c++ - 取消声明函数中使用的结构成员?

c++ - 结构和函数(通过引用传递)

c - C中的函数参数