node *p=NULL和p->link=NULL是什么关系?
p->link=0和p->link=NULL是一回事吗?
#include<iostream>
using namespace std;
struct Node{
int data;
Node *next;
};
int Insert(Node *&myList,int value){
Node *newnode=new Node;
newnode->data=value;
newnode->next=myList;
myList=newnode;
return 1;
}
int Find(Node *p,int value)
{
int m=0;
while(p!=NULL&&p->data!=value)
{
p=p->next;
m++;
}
return m;
}
void Pout(Node *p)
{
if(p->next==0)cout<<"链表空!";
while(p!=0)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
void main(){
int temp;
Node *head=NULL;
Insert(head,7);
Insert(head,5);
Insert(head,3);
Insert(head,1);
Insert(head,9);
Pout(head);
temp=Find(head,9);
cout<<"temp="<<temp<<endl;
temp=Find(head,7);
cout<<"temp="<<temp<<endl;
cout<<endl;
system("pause");
}
node *p=NULL是合法的
追答你的p指针不是指向一个结构体?
当p指向一个结构体时是不合法的
我使用VS2010和TC都试过
你看问题补充里的程序,是可以运行的
追答Node *head=NULL;
是指针的声明与初始化……
功能上等价于下面的语句
Node *head;
head=NULL;
就是head=NULL是什么意思啊。。。不是link=null吧?
追答node *p=NULL;//指针p指向地址为0的内存空间
和
p->link=NULL;//指针p指向一个对象,该对象中有一个指针link指向了地址为0的内存空间
这两个没什么关系