Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c中的链表中创建链表_C_Linked List_Structure - Fatal编程技术网

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

如何在c中的链表中创建链表,c,linked-list,structure,C,Linked List,Structure,我想创建一个主列表,每个主列表元素都有另一个列表 这就是我所做的 typedef struct smallList { char data; struct smallList *next; } small; typedef struct bigList { int count; char data; struct bigList *next; struct sma

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

这就是我所做的

    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->head
    是bigList指向的小列表
  • (bigList->head)。数据是smallList包含的字符
    
  • (bigList->next->head)
    是bigList中的第二个小列表
  • (bigList>head->next)
    是bigList的第一个smallList中的第二个元素

在获得指向要修改的结构的指针后,其他所有内容都是一样的。

嘿,老兄,我听说你喜欢链表,所以我们在链表中创建了一个链表,这样你可以在遍历另一个链表时享受链表。这听起来像昨天的问题()海报需要制作一个链表,每个项目都有一个班级作业的链表。当时没有得到回复。谢谢你的帮助。“your_big_list()”是否返回大列表中第一个元素(或任何元素)的地址。@user1476263:我可能会将其用于列表的第一个元素,但它将从任何给定元素开始迭代到列表的末尾。