1、createlist不是库函数,一般是数据结构中实现新建一个链表的自定义函数。因此没有什么用法好说的,关键是看自己怎么定义。
2、例程:
NODE *creatlist(int a[]){ NODE *h,*p,*qint i
h=(NODE *)malloc(sizeof(NODE))
h->next=NULL
for(i=0i<Ni++)
{q=(NODE *)malloc(sizeof(NODE))
q->data=a[i]
q->next=NULL
if(h->next==NULL) h->next=p=q
else {p->next=qp=q} }
return h
}
你说的如果是自定义函数。就先写出来,比如
#include<stdio.h>void create()
{
//这里写函数代码
}
int main()
{
create()//在主函数里进行调用
}
#include <stdio.h>#include <malloc.h>
#include <string.h>
#define N 5
typedef struct node
{
char number[10]
int data
struct node *next
}node
node * create()
{
node *p,*s,*hchar number[10]
int j=1,x
p=s=h=(node*)malloc(sizeof(node))
h->next=NULL
printf("please input the data to create the list,end with -1 or %d numbers\n",N)
while(x!=-1&&j<=N)
{
printf("input name:")
scanf("%s",number)
printf("input age:")
scanf("%d",&x)
s=(node*)malloc(sizeof(node))
s->data=x
strcpy(s->number,number)
if(h->next==NULL)
h->next=s
else
p->next=s
p=s
j++
}
p->next=NULL
return h
}
int main()
{
node *p
p=create()
return 0
}