观郝斌老师视频链表 !求助!
#include<stdio.h>#include<malloc.h>
#include<stdlib.h>
struct Nobe
{
int val;
struct Nobe * pnext;
};
struct Nobe * inoutlist()
{
int val;
int i;
int n;
struct Nobe * p = (struct Nobe *)malloc(sizeof(struct Nobe));
if(NULL == p)
{
printf("分配失败");
exit(-1);
}
struct Nobe * ptail = p;
ptail->pnext = NULL;
printf("请输入个数:");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("请输入第%d个数字:",i+1);
scanf("%d",&val);
struct Nobe * p1 ;
p1 = (struct Nobe *)malloc(sizeof(struct Nobe));
if(NULL == p1)
{
printf("分配失败");
exit(-1);
}
p1->val = val;
ptail->pnext = p1;
p1->pnext = NULL;
ptail = p1;
}
return p;
}
void inputlist(struct Nobe * p)
{
struct Nobe * q = p->pnext;
while(NULL != q)
{
printf("%d\n",q->val);
q = q->pnext;
}
}
main()
{
struct Nobe * p = NULL;
p = inoutlist();
inputlist(p);
}