C语言中的链表数组

C语言中的链表数组,c,arrays,C,Arrays,我在制作一系列链表时遇到了困难。我有这个结构 typedef struct node { int id; struct node * next; } t_point; t_point* array[10]; 例如,我想让数组[0]指向链表的头,然后填充,对数组的所有空间重复这个过程 我知道我需要如何编写代码,但我不能把它做好。我只想有人给我看一下并解释一下语法。类似这样的东西: t_point* array[10] void link_list() { int ar

我在制作一系列链表时遇到了困难。我有这个结构

typedef struct node {
    int id;
    struct node * next;
} t_point;

t_point* array[10];
例如,我想让数组[0]指向链表的头,然后填充,对数组的所有空间重复这个过程

我知道我需要如何编写代码,但我不能把它做好。我只想有人给我看一下并解释一下语法。

类似这样的东西:

t_point* array[10]

void link_list()
{
    int array_length = sizeof(array) / sizeof(t_point*);

    // Allocate the memory for the first list item
    array[0] = malloc(sizeof(t_point));

    // Iterate through each item in `array` and allocate it some memory
    for (int i = 1; i < array_length; i++)
    {
        // Allocate memory for the next item
        array[i] = malloc(sizeof(t_point));

        // Set the previous item's `next` field to the current item pointed to by `i`
        array[i - 1]->next = array[i];
    }

    // Close the list by adding a NULL pointer
    array[array_length - 1]->next = NULL;
}
t_点*阵列[10]
无效链接列表()
{
int array_length=sizeof(array)/sizeof(t_point*);
//为第一个列表项分配内存
数组[0]=malloc(sizeof(t_点));
//遍历“array”中的每个项并为其分配一些内存
for(int i=1;inext=数组[i];
}
//通过添加空指针关闭列表
数组[array_length-1]->next=NULL;
}

还要记得
释放
malloc
的内存,否则会导致内存泄漏。我将由您决定。

欢迎来到stack overflow!请向我们展示您尝试过的内容,以及哪些部分会给您带来麻烦,这样我们可以帮助您在纸上绘制您想要的内容,并用方框表示结构,箭头表示指针。语法应该由您的老师/导师解释。你还可以在网上找到很多关于链表的教程。@JoachimPileborg:Huh?然后几十年来我一直在做错事。我用胖点表示指针,用箭头表示关系;-)谢谢,解释英语不是你的母语,在这里都是不必要的(还有两个拼写错误,在关于它的信息中;-)(对不起,英语))这真的很有帮助!谢谢大家!@Gabriel如果这有帮助,请接受答案