有两个,第二个写了些注释,你自己看一下觉得哪个理解的好
方法一:
#include #include #include #include using?namespace?std; class?CData { public: CData(){}; virtual?int?comparename(CData?&)?=0; virtual?void?show()=0; virtual?~CData(){}; }; class?CNode { public: CNode(){pdata=0;pnext=0;} CNode(CNode?&n); void?inputdata(CData?*pd){pdata=pd;} void?shownode(){pdata->show();} CData?*getdata(){return?pdata;} friend?class?CList; private: CData?*pdata; CNode?*pnext; }; CNode::CNode(CNode?&n) { pdata=n.pdata; pnext=n.pnext; } ? class?CList { public: CList(){phead=0;} ~CList(){deletelist();} void?addnode(CNode?*pnode); void?deletelist(); CNode?*deletenode(CNode?*pnode); CNode?*lookup(CData?&data); CNode?*getlisthead(){return?phead;} void?showlist(); CNode?*getnext(CNode?*pnode); private: CNode?*?phead; }; void?CList::addnode(CNode?*pnode) { if(phead==0) { phead=pnode; pnode->pnext=0; return; } else { pnode->pnext=phead; phead=pnode; } } void?CList::deletelist() { CNode?*p1,*p2; p1=phead; while(p1) { delete?p1->pdata; p2=p1; p1=p1->pnext; delete?p2; } } CNode?*CList::deletenode(CNode?*pnode) { CNode?*p1,*p2; ????p1=phead; while(p1!=pnode&&p1->pnext!=0) { p2=p1; p1=p1->pnext; } if(p1==phead) { phead=phead->pnext; return?pnode; } p2->pnext=p1->pnext; return?pnode; } CNode?*CList::lookup(CData?&data) { CNode?*p1=phead; while(p1) { if(p1->pdata->comparename(data)==0) return?p1; ????????p1=p1->pnext;??? } return?0; } void?CList::showlist() { if(phead==0) cout<pdata->show(); ????p=p->pnext; } } } CNode?*CList::getnext(CNode?*pnode) { CNode?*p=pnode; p=p->pnext; ????return?p; } class?Student:public?CData { private: char?s_class[17]; char?s_num[17]; char?s_name[17]; double?ele_technique; double?c_program; double?mul_technique; ????double?col_english; double?sen_math; double?col_gym; double