摘要:复数的完整C++实现//Author:KeithA.Shomper//Date:11/17/03//Purpose:Todemonstrateaclass#includeusingstd::cout;usingstd::cin;usingstd::endl;usingstd::ostream;usingstd::istream;classcomplex_number{public:complex_number(doublereal=0.0,doubleimag=0.0):r(real),i(imag){}complex_number(constcomplex_number&rhs):r 阅读全文
posted @ 2012-08-24 10:48 Mr.Rico 阅读 (117) 评论 (0) 编辑
摘要:C实现的二叉搜索树/**二叉搜索树*/#include#include#include#defineTRUE1#defineFALSE0typedefintBOOL;typedefstructNode{structNode*left,*right;size_tsize;chardata[];}Node_t;typedefconstvoid*GetKeyFunc_t(constvoid*dData);typedefintCmpFunc_t(constvoid*pKey1,constvoid*pKey2);typedefstruct{structNode*pRoot;CmpFunc_t*cmp;G 阅读全文
posted @ 2012-08-24 10:47 Mr.Rico 阅读 (77) 评论 (0) 编辑
摘要:Stack的一种实现/**stack实现:利用vector*/#include#include#includeusingstd::cout;usingstd::endl;usingstd::vector;usingstd::string;usingstd::ostream;templateclassStack{public:Stack(intcap=0){if(cap)_stack.reserve(cap);}boolpop(T&vaulue);boolpush(Tvalue);boolfull();boolempty();voiddisplay();intsize();private 阅读全文
posted @ 2012-08-24 10:46 Mr.Rico 阅读 (88) 评论 (0) 编辑
摘要:利用引用计数的实现方式#include#include#include#definemax(x,y)((x)>(y)?(x):(y))#definemin(x,y)((x)(len*1.5,n);size_tnewlen=needed?4*((needed-1)/4+1):0;char*newbuf=newlen?newchar[newlen]:0;if(buf){strncpy(newbuf,buf,used);}delete[]buf;buf=newbuf;len=newlen;}}classString{friendistream&operator>>(istr 阅读全文
posted @ 2012-08-24 10:42 Mr.Rico 阅读 (137) 评论 (0) 编辑
摘要:自动进行空间扩展/**TheimplementationofStringlikevector*/#include#include#include#definemax(x,y)((x)>(y)?(x):(y))#definemin(x,y)((x)>(istream&,String&);friendostream&operator(constString&)const;booloperator>=(constString&)const;booloperator(constchar*)const;booloperator>=(cons 阅读全文
posted @ 2012-08-24 10:41 Mr.Rico 阅读 (89) 评论 (0) 编辑
摘要:这是最基本的String的实现/**ThebasicimplementationofString*/#include#include#includeusingstd::istream;usingstd::ostream;usingstd::cout;usingstd::endl;usingstd::cin;usingstd::setw;classString{public:friendistream&operator>>(istream&,String&);friendostream&operator(constString&)const;b 阅读全文
posted @ 2012-08-24 10:40 Mr.Rico 阅读 (50) 评论 (0) 编辑
摘要:JM中的有用程序#if0/**1.dct方法*/#include#include#include#defineM16#defineBLOCK_SIZE4staticinttmp[M];voidforward4x4(int(*block)[M],int(*tblock)[M],intpos_y,intpos_x){inti,ii;int*pTmp=tmp,*pblock;staticintp0,p1,p2,p3;staticintt0,t1,t2,t3;//Horizontalfor(i=pos_y;i#include#include#defineM16#defineBLOCK_SIZE4sta 阅读全文
posted @ 2012-08-24 10:37 Mr.Rico 阅读 (96) 评论 (0) 编辑
摘要:linux下的示例程序#if0/**1.遍历目录-1*/#include#include#include#includevoidshow_directory(char*path){DIR*dir;structdirent*entry;staticintcount=0;inti=0;intj=0;if(NULL==(dir=opendir(path)))printf("erroropeningdir\n");else{chdir(path);//system("pwd");count+=1;while(entry=readdir(dir)){//if(st 阅读全文
posted @ 2012-08-24 10:36 Mr.Rico 阅读 (153) 评论 (0) 编辑
摘要:C++的示例程序:1.#if0/*1.C++中整数/浮点等转化为字符串*/#include//forthe//forostringstream#include//forstringtemplatestd::stringto_string(Tconst&obj){std::ostringstreamout;out//forthe>>operator#include//forostringstream#include//forstringtemplateTfrom_string(std::stringconst&str){std::istringstreamin(str 阅读全文
posted @ 2012-08-24 10:28 Mr.Rico 阅读 (133) 评论 (0) 编辑