Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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_List_Function_Linked List - Fatal编程技术网

C 函数中的链表

C 函数中的链表,c,list,function,linked-list,C,List,Function,Linked List,我想写一个c代码,其中有一些参数的长度没有定义,可能会在代码中更改。所以我知道我必须用链表来表示这些变量。 问题是我不知道如何将它们声明为函数的参数。例如,我们对整数变量使用“int”。我如何申报一份清单 请给出一个例子来定义一个列表并在函数中使用它们(只是函数的第一行)。 请考虑我使用以下链表< /P>声明类型 typedef struct node_type{ int data; struct node_type *next; } node; typedef node

我想写一个c代码,其中有一些参数的长度没有定义,可能会在代码中更改。所以我知道我必须用链表来表示这些变量。 问题是我不知道如何将它们声明为函数的参数。例如,我们对整数变量使用“int”。我如何申报一份清单

请给出一个例子来定义一个列表并在函数中使用它们(只是函数的第一行)。 请考虑我使用以下链表< /P>声明类型
typedef struct node_type{
    int data;
    struct node_type *next;
    } node;
typedef node *list;

谢谢

您可以将内存分配给列表的节点,如下所示

node *ptr = (node*)malloc(sizeof(node));
您可以将函数中列表的节点传递为

some_function(&ptr);
函数定义为

void some_function(node **pointer)

实际上,我对链表的定义如下:typedef struct node_type{int data;struct node_type*next;}node;typedef节点*列表;我如何使用这种格式