学习链表的时候写的代码.编译的时候没问题,运行就报错.大神帮看看.谢谢!!
#include<iostream>
#include<string>
using namespace std;
struct student
{
int id;
string name;
student* next;
};
student thehead={0}; //定义一个对象做为链表头节点
student tinsert={107,"a7",0};
void insertlistlast(student* addlist) //在最后一个节点后面插入一个新节点.
{
student* tpoint=&thehead;
while(tpoint->next) //循环用于遍历链表找到最后节点.
tpoint=tpoint->next;
addlist->next=tpoint->next;
tpoint->next=addlist;
}
void addmalloclist(/*int id,string name*/) //创建临时对象插入链表,通过malloc函数新增节点
{
student* tpoint=(student*)malloc(sizeof(student));
tpoint->id=108;
tpoint->name="a8"; //分步调试的时候 在这一步报错了...
insertlistlast(tpoint);
}
int main()
{
insertlistlast(&tinsert);
int inid=108;
string inname="a8";
addmalloclist(/*inid,inname*/);
return 0;
}
#include<iostream>
#include<string>
using namespace std;
struct student
{
int id;
string name;
student* next;
};
student thehead={0}; //定义一个对象做为链表头节点
student tinsert={107,"a7",0};
void insertlistlast(student* addlist) //在最后一个节点后面插入一个新节点.
{
student* tpoint=&thehead;
while(tpoint->next) //循环用于遍历链表找到最后节点.
tpoint=tpoint->next;
addlist->next=tpoint->next;
tpoint->next=addlist;
}
void addmalloclist(/*int id,string name*/) //创建临时对象插入链表,通过malloc函数新增节点
{
student* tpoint=(student*)malloc(sizeof(student));
tpoint->id=108;
tpoint->name="a8"; //分步调试的时候 在这一步报错了...
insertlistlast(tpoint);
}
int main()
{
insertlistlast(&tinsert);
int inid=108;
string inname="a8";
addmalloclist(/*inid,inname*/);
return 0;
}

