YangDS7 2020-03-08 19:47 采纳率: 0%
浏览 414

新手小白问一下为什么我的链表打印不出来

#include
#include
using namespace std;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define Status int
#define ElemType int
#define OK 1
#define INFEASIBLE -1
typedef struct LNode{
ElemType data;
struct LNode*next;
}LNode,*LinkList;
Status Create(LNode*phead,int length);
Status Put(LNode*phead);
void main()
{
LNode*head;
Create(head,3);
Put(head);
}
Status Create(LNode*phead,int length)
{
LNode*pnew;
phead=NULL;
for(int i=0;i {
pnew=(LNode*)malloc(sizeof(LNode));
scanf("%d",&pnew->data);
if(phead==NULL)
{
phead=pnew;
pnew=pnew->next;
}
else
pnew=pnew->next;

}
pnew=NULL;
return OK;

}
Status Put(LNode*&phead)
{
LNode*pcur;
for(pcur=phead;pcur!=NULL;pcur=pcur->next)
printf("%d",pcur->data);
return OK;
}

  • 写回答

2条回答 默认 最新

  • tawufa 2020-03-08 22:15
    关注

    大致看来一下,应该是 Create(LNode*phead,int length)函数的问题,你这里参数LNode*phead;之后你运行了一句phead=NULL肯定不行的。

    评论

报告相同问题?

悬赏问题

  • ¥20 Html备忘录页面制作
  • ¥15 黄永刚的晶体塑性子程序中输入的材料参数里的晶体取向参数是什么形式的?
  • ¥20 数学建模来解决我这个问题
  • ¥15 计算机网络ip分片偏移量计算头部是-20还是-40呀
  • ¥15 stc15f2k60s2单片机关于流水灯,时钟,定时器,矩阵键盘等方面的综合问题
  • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
  • ¥30 NIRfast软件使用指导
  • ¥20 matlab仿真问题,求功率谱密度
  • ¥15 求micropython modbus-RTU 从机的代码或库?
  • ¥15 django5安装失败