#include "D:\TCPP30E\Project\CLNode.cpp"
#include
void main()
{ clrscr();
CLNode s1("first"), s2("second"), s3("third"), s4("fourth");
s2.insert(s1);
s3.insert(s2);
s4.insert(s3);
CLNode * pn;
pn = s4.get();
pn->print();
pn=pn->get();
pn->print();
pn=pn->get();
pn->print();
pn=pn->get();
pn->print();
CLNode ss("newcode");
ss.insert(s3);
pn = s4.get();
pn->print();
pn=pn->get();
pn->print();
pn=pn->get();
pn->print();
pn=pn->get();
pn->print();
pn=pn->get();
pn->print();
}
程序中新声明了一个ss新的字符串,插入了s3的后面
如果我想修改程序,由我手动输入,插入指定的节点后面,要如何修改?
我是菜鸟,望达人指教;
类已经声明好了.如下:
#include
#include
class CLNode
{ char *ps;
CLNode *next;
public:
CLNode(char * str);
void insert(CLNode & obj);
CLNode * get(void);
void print(void);
};
CLNode::CLNode (char * str)
{ ps=new char(strlen(str)+1);
strcpy(ps,str);
next=NULL;
}
void CLNode::insert(CLNode & c)
if (c.next!=NULL)
next = c.next;
else
next = & c;
c.next = this;
}
CLNodeL * CLNode::get(void)
{ return next; }
void print(void)
{ cout<<"第"<
--------------------next---------------------
阅读(1088) | 评论(0) | 转发(0) |