1 / 45
文档名称:

数据结构与算法ppt课件.ppt

格式:ppt   大小:244KB   页数:45
下载后只包含 1 个 PPT 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

数据结构与算法ppt课件.ppt

上传人:相惜 2020/6/1 文件大小:244 KB

下载得到文件列表

数据结构与算法ppt课件.ppt

相关文档

文档介绍

文档介绍:-(String)字符串是n(0)个字符的有限序列,记作S:“”其中,S是串名字“”是串值ci是串中字符n是串的长度。=128; classString{intcurLen;//串的当前长度 char*ch;//串的存储数组public:String(constString&ob);String(constchar*init);String();~String(){delete[]ch;}intLength()const{returncurLen;}&operator()(intpos,intlen);intoperator==(constString&ob)const{returnstrcmp(ch,)==0;}intoperator!=(constString&ob)const{returnstrcmp(ch,)!=0;}intoperator!()const{returncurLen==0;}String&operator=(constString&ob);String&operator+=(constString&ob);char&operator[](inti);intFind(Stringpat)const;}::String(constString&ob){//复制构造函数:从已有串ob复制ch=newchar[maxLen+1];if(!ch){cout<<“AllocationError\n”;exit(1);}curLen=;strcpy(ch,);}::String(constchar*init){//复制构造函数:从已有字符数组*init复制ch=newchar[maxLen+1];if(!ch){cout<<“AllocationError\n”;exit(1);}curLen=strlen(init); strcpy(ch,init); }::String(){//构造函数:创建一个空串ch=newchar[maxLen+1];if(!ch){cout<<“AllocationError\n”;exit(1);}curLen=0;ch[0]=‘\0’;}+len-1 pos+len-1curLen-1&String::operator()(intpos,intlen){//从串中第pos个位置起连续提取len个字符//形成子串返回 if(pos<0||pos+len-1>=maxLen||len<0){=0;//[0]='\0';}else{//提取子串 String*temp=newString;//(pos+len-1>=curLen)len=curLen-pos; temp→curLen=len;//子串长度 for(inti=0,j=pos;i<len;i++,j++) temp→ch[i]=ch[j];//传送串数组 temp→ch[len]=‘\0’;//子串结束}returntemp;}10.