分享到:
发表于 2010-08-11 22:11:17 楼主 | |
/**************** ****node.h******* ****************/ #include using namespace std; class node { friend class linklist; friend void shownode(node &n); public: node(); node(node &n); node(int i,char c='0'); node(int i,char c,node *p,node *n); int readi() const; char readc() const; node * readp() const; node * readn() const; bool set(int i); bool set(char c); bool setp(node *p); bool setn(node *n); ~node(); static int allocetion(); private: int idata; char cdata; node *prior; node *next; static int count; }; /***************** ***node.cpp******* *****************/ #include"node.h" #include using namespce std; int node::count=0 int node::readi() const { return idata; } char node::readc() const { return cdata; } node *node::readp() const { return prior; } node *node::readn() const { return next; } bool node::set(char c) { cdata=c; return true; } bool node::set(int i) { idata=i; return true; } bool node::setp(node *p) { prior=p; return true; } bool node::setn(node *n) { next=n; return true; } node::node() { cout<<"node constructor is runing..."< cdata='0'; prior=NULL; next=NULL; count++; } node::node(int i,char c) { cout<<"node constructor is runing..."< cdata=c; prior=NULL; next=NULL; count++; } node::node(int i,char c,node *p,node *n) { cout<<"node constructor is runing..."< cdata=c; prior=p; next=n; count++; } node::node(node &n) { count++; idata=n.idata; cdata=n.cdata; prior=n.prior; next=n.next; } node::~node() { cout--; cout<<"node destructor is running..."< int node allocetion() { return count; } void shownode(node &n) { cout<<"n.idata"<<'t'< /*************** ****linklist.h** ***************/ #include"node.h" #include using namespace std; class linklist { public: linklist(int i,char c); linklist(linklist &l); ~linklist(); bool locate(int i); bool locate(char c); bool insert(int i=0,char c='0'); bool Delete(); void show(); void Destroy(); private: node head; node * pcurrent; }; linklist::linklist(int i,char c):head(i,c) { cout<<"linklist constructor is runing..."< } linklist::linklist(linklist &l):head(l.head) { cout<<"linklist deep cloner running..."< node * ptemp1=l.head.next; while(ptemp1!=NULL) { node * ptemp2=new node(ptemp1->idata,ptemp1->cdata,pcurrent,NULL); pcurrent->next=ptemp2; pcurrent=pcurrent->next; ptemp1=ptemp1->next ; } } linklist::~linklist() { cout<<"linklist destructor is running..."< } bool linklist::locate(int i) { node *ptemp=&head while(ptemp!=NULL) { if(ptemp->readi()==i) { pcurrent=ptemp; return true; } ptemp=ptemp->readn(); } return false; } bool linklist::locate(char c) { node *ptemp=&head while(ptemp!=NULL) { if(ptemp->readc()=='c') { pcurrent=ptemp; return true; } ptemp=ptemp->readn(); } return false; } bool linklist::insert(int i,char c) { if(pcurrent!=NULL) { node * temp=new node(i,c,pcurrent,pcurrent->readn()); if(pcurrent->readn()!=NULL) { pcurrent->readn()->setp(temp); } pcurrent->setn(temp); return true; } else { return false; } } bool linklist::Delete() { if(pcurrent!=NULL&&pcurrent!=&head) { node * temp=pcurrent; if(temp->readn()!=NULL) { temp->readn()->setp(pcurrent->readp()); } temp->readp()->setn(pcurrent->readn()); pcurrent=temp->readp(); delete temp; return true; } else { return false; } } void linklist::show() { node * ptemp=&head while(ptemp!=NULL) { cout< } } void linklist::Destroy() { node * ptemp1=head.readn(); while (ptemp1!=NULL) { node * ptemp2=ptemp1->readn(); delete ptemp1; ptemp1=ptemp2; } head.setn(NULL); } /****************** *****main.cpp****** ******************/ #include "stdafx.h" #include #include"linklist.h" using namespace std; int main() { int tempi; char tempc; cout<<"请输入一个整数和字符"< linklist a(tempi,tempc); a.locate(tempi); a.insert(1,'c'); a.insert(2,'b'); cout<<"after insert"< node b(4,'f'); cout<<"an independent node created"< return 0; } //但是程序却说 c:program filesmicotsoft visul studiomy projiectsmainnode.cpp(89);fatal error c1010:unexpected end of file while looking for precompiled header directive 执行 c1.exe时出错。 main.exe-1 error(s),0 warning(s) 小弟初学c++,对于其中的错误百思不得其解,请高手赐教 |
|
楼主热贴
个性签名:无
|
发表于 2010-08-11 22:14:46 1楼 | |
#include |
|
发表于 2010-08-11 22:15:31 2楼 | |
iostream表示不出来? | |
发表于 2010-08-11 22:24:32 3楼 | |
程序中的endl;也不见了? | |
发表于 2010-08-23 10:27:31 4楼 | |
#include后面的引用呢? | |
发表于 2010-08-30 09:53:09 5楼 | |
支持下楼主 | |
发表于 2010-09-10 08:35:26 6楼 | |
楼主蛮厉害的 程序这么长哦 | |
发表于 2010-09-19 21:41:24 7楼 | |
您的内容正在火速审核中,请稍等 |
|
发表于 2010-09-22 08:57:03 8楼 | |
include后面忘加了iosterom(输入输出流定义) | |
发表于 2010-09-30 22:29:29 9楼 | |
学习 | |
发表于 2010-10-07 10:02:11 10楼 | |
您的内容正在火速审核中,请稍等 |
|
针对ZOL星空(中国)您有任何使用问题和建议 您可以 联系星空(中国)管理员 、 查看帮助 或 给我提意见