来人帮我看看,不知道什么错误,关于链表的
#include <iostream>
using namespace std;
class listnode
{
private:
friend class list;
int data;
listnode* link;
listnode (){}
listnode(const int item):data(item),link(NULL){}
};
class list
{
listnode *frist,*currcent;
public:
list():frist(NULL),currcent(NULL) {}
~list() {}
listnode * NewNode ( const int item )
{//创建新链表结点
listnode *newnode = new listnode (item);
return newnode;
}
void newnode(listnode* frist)
{ int value;
frist=NULL;
listnode *p;
cout < < "Input your data:\n ";
cin> > value;
while(value!=0) //0为结束标志
{
p=NewNode(value); //为新分配节点指定空间
if(frist==NULL) {frist=currcent=p;}
else
{
//cout < < "p== " < <(void*)p < <endl;
currcent-> link=p; //currcent-> link的值始终是NULL,不知为何??
currcent=p;
}
cin.clear();
cin.sync();
cin> > value;
}
currcent-> link=NULL;
}
void printlist()
{
cout < < "\nThe list is:\n ";
listnode *p=frist;
while(p!=NULL)
{
cout < <p-> data < < ' ';p=p-> link;//打印输出
}
cout < < "\n ";
}
};
int main()
{
list node;
node.newnode(NULL);
node.printlist();
return 0;
}
[解决办法]
看代码似乎没有错,一会儿调试一下。
[解决办法]
因为currcent指向新分配的p,而p中的link初始化为NULL
currcent拼写错误吧 应该是current
[解决办法]
tangshuiling() ( )
倒没注意到参数上去,呵呵。
不过你这个程序拼写错误可够多的。
我还在下载mingw呢,你都解决了。家里没装环境。