wei___123 2017-09-28 02:58 采纳率: 75%
浏览 781

C语言链表问题求解,还有个函数类型不知道用什么

#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 什么的都是错的

  • 写回答

1条回答 默认 最新

  • 仅仅学会简单 2017-09-28 05:58
    关注

    不是很明白你的问题,图片也没有上传好,我试了下没有什么明显的问题额。

    评论

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面