一道数据编程请路过的大虾help me !
#include <iostream.h>
#include <malloc.h>
typedef struct List
{
int data;
struct List *next;
}List;
struct List *init(struct List *head,int j)
{
struct List* cur;
cur=head;
struct List *student=(struct List *)malloc(sizeof(struct List));
student-> data=j;
while(cur-> next!=NULL)
{
cur=cur-> next;
}
cur-> next=student;
return head;
}
struct List *show(struct List *head)
{
struct List *cur;
cur=head;
while(cur!=NULL)
{
cout < <cur-> data < <endl;
cur=cur-> next;
}
return head;
}
int main()
{
int num;
char order;
struct List *head;
head=(struct List *)malloc(sizeof(struct List));
cout < < "输入操作符 ";
cin> > order;
if(order== 'i ')
{
cout < < "请输入要存储的数字! ";
cin> > num;
head-> data=num;
}
cout < < "输入操作符 ";
cin> > order;
while(order== 'i ')
{
cout < < "请输入要存储的数字! ";
cin> > num;
init(head,num);
cout < < "输入操作符 ";
cin> > order;
}
cout < < "what 's do you do! ";
cin> > order;
if(order== 'o ')
{
show(head);
}
return 0;
}
[解决办法]
关键是你一开始链表就没有构造成功。