在创建n个链表时,错误却说p没有初始化,这是怎么回事啊?

[复制链接]
查看11 | 回复5 | 2008-7-7 00:20:04 | 显示全部楼层 |阅读模式
#include
using namespace std;
struct node
{
int data;
struct node *next;
};
void creat(node *&head,int n)//创建有n个节点的链表
{
if(n==0)
{
head=NULL;
return;
}
cout>x;

P->data=x;
p->next=NULL;
head=last=p;
if(n==1)return;
for(i=1;inext=p;
cin>>x;
p->data=x;
last=p;
}
p->next=NULL;
for(int j=1;jdatanext=p;
p++;
}
}
void main()
{
node *a=NULL;
int n;
cout>n;

creat(a,n);
}
错误:
E:\programs\lian biao\lian biao.cpp(22) : error C2065: 'P' : undeclared identifier
E:\programs\lian biao\lian biao.cpp(22) : error C2227: left of '->data' must point to class/struct/union

回复

使用道具 举报

千问 | 2008-7-7 00:20:04 | 显示全部楼层
#include using namespace std; struct node { int data; struct node *next; }; void creat(node *head,int n)//创建有n个节点的链表 { if(n==0) { head=NULL; return; } cout>x; p->data=x; p->next=NULL; head=l
回复

使用道具 举报

千问 | 2008-7-7 00:20:04 | 显示全部楼层
void creat(node *&head,int n)你这声明的都什么函数啊……把&去掉吧,不然还是个错。
回复

使用道具 举报

千问 | 2008-7-7 00:20:04 | 显示全部楼层
node *last,*p;last=head=NULL;p=new node;cin>>x;P->data=x;
//这里错了,之前定义的是小写的pp->next=NULL;
回复

使用道具 举报

千问 | 2008-7-7 00:20:04 | 显示全部楼层
乱七八糟的程序,应该被54
回复

使用道具 举报

千问 | 2008-7-7 00:20:04 | 显示全部楼层
注意你程序中是大写的P你定义的是小写的p....
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行