链表的建立,和输出为什么会崩溃,,
程序代码:
#include<iostream> #include"liuyu.hpp" using namespace std; int main(){ liuyu *L; build_(L); display_(L); return 0; }
程序代码:
#include<iostream> class liuyu{ public: char data; liuyu *next; }; //建立链表 void build_(liuyu *L) { L=new liuyu; L->next=NULL; liuyu *p; p=new liuyu; while(std::cin>>p->data){ p->next=L->next; L->next=p; p=new liuyu; } } //输出链表 void display_(liuyu *L){ liuyu *p=L; while(p->next!=NULL){ p=p->next; std::cout<<p->data<<" "; } }
按照C语言的数据结构书改动,,无力啊,自己找不出错