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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python