#include
#include
#include
struct LNode
{
int data;
struct LNode *next;
};
struct LNode *creat(int n)
{
int i;
struct LNode *head, *p1, *p2;
int a;
head=NULL;
printf("Input the integers:\n");
for(i=n;i>0;--i)
{
p1=(struct LNode *)malloc(sizeof(struct LNode));
scanf("%d",&a);
p1->data=a;
if(head==NULL)
{
head=p1;
p2=p1;
}
else
{
p2->next=p1;
p2=p1;
}
}
p2->next=NULL;
return head;
}
int main()
{
int n;
struct LNode *q;
printf("Input the count of the nodes you want to creat;");
scanf("%d",&n);
q=creat(n);
printf("The result is:\n");
while(q)
{
printf("%d ",q->data);
q=q->next;
}
getch();
}
求大神解释下,比如我限定3个链表。输入1 2 3 ,怎么输出 1 2 3 的下面是我调试得来的数据![图片说明](https://img-ask.csdn.net/upload/20170
9/28/1506567138_890471.png)求大神解释下,为什么?这个是尾插 吧
还有一个问题
void showall (node *phead)
{
if(phead==NULL)
{
return;
}
else
{
printf("%d;%p->%p\n",phead->data,phead,phead->pnext);
showall(phead->pnext);
}
}这里的函数类型用什么。void,int 什么的都是错的