繁体   English   中英

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

[英]how to create a linked list inside a linked list in c

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

这就是我所做的

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

如果p指向bigList:

  • bigList -> head是bigList指向的小列表。
  • (bigList -> head).data是smallList包含的字符。
  • (bigList -> next -> head)是bigList中的第二个smallList。
  • (bigList > head -> next)是bigList的第一个smallList中的第二个元素。

获取指向要修改的结构的指针后,其他所有内容都相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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