typedef struct node
{
int data;
struct node *next;
}Node;
Node *createNode(void)
{
Node *head=NULL;
Node *p=NULL;
Node *q=NULL;
int i=0;
int n=0;
printf("\n请输入链表的长度:");
scanf("%d",&n);
if((head=(Node *)malloc(sizeof(Node)))==NULL)
{
printf("分配内存失败\n");
exit(0);
}
head->data=n;
head->next=NULL;
p=head;
printf("请输入这%d个整数,以q结束:\n",n);
for(i=0; i {
if((q=(Node *)malloc(sizeof(Node)))==NULL)
{
printf("分配内存失败\n");
exit(0);
}
scanf("%d\n",&(q->data));
q->next=NULL;
p->next=q;
p=q;
}
p->next=NULL;
return head;
}
阅读(1110) | 评论(0) | 转发(0) |