#include<iostream.h>
class node//
{
public:
node *next;
int data;
node(const int & item ,node *ptrnext=NULL);//构造
void insertafter(node*p);//插入
node *thisnode(void);//返回本节点的指针
};
node::node(const int&item,node *ptrnext)
{
data=item;
next=ptrnext;
}
void node::insertafter(node*lastptr)
{
lastptr->next=this->next;
this->next=lastptr;
}
node *node::thisnode(void)
{return this;}
void main()
{
int a,i;
node *lastptr,*head,*currptr; cout<<"please input a: "<<endl;
cin>>a;
node example1(a);
head=example1.thisnode();
currptr=head;
for(i=0;i<9;i++)
{
lastptr=example1.thisnode();
cin>>a;
node example1(a);
example1.insertafter(lastptr);
}
cout<<endl;
while (currptr!=NULL)
{
cout<<currptr->data;
currptr=currptr->next;
}
}
请问这个程序应怎样修改?谢谢
本文地址:http://com.8s8s.com/it/it1036.htm