我这链表程序哪错了?

[复制链接]
查看11 | 回复5 | 2012-8-27 18:47:25 | 显示全部楼层 |阅读模式
#include #include using namespace std;typedef struct node{ int number; char name[20]; struct node *next;}node;int main(){ node *head=NULL; node *end=head; node *current; char c='a'; do {if(head==NULL){ head=new node[sizeof(node)]; end=head; cout<<"创建头结点中..."...
回复

使用道具 举报

千问 | 2012-8-27 18:47:25 | 显示全部楼层
没分配内存,用malloc分配内存吧!...
回复

使用道具 举报

千问 | 2012-8-27 18:47:25 | 显示全部楼层
结构体没有分配内存啊~...
回复

使用道具 举报

千问 | 2012-8-27 18:47:25 | 显示全部楼层
没为head申请空间吧,他是null,不能直接使用,要 head = new struct node;...
回复

使用道具 举报

千问 | 2012-8-27 18:47:25 | 显示全部楼层
head没申请空间就直接赋值,肯定崩溃!你的C语言的基础需要再补补才行。...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行