数据结构c语言版(串)浅析.ppt

第四章 串 通常将子串在主串中首次出现时的该子串的首字符对应的主串中的序号,定义为子串在主串中的序号(或位置)。例如,设A和B分别为 A=“This is a string” B=“is” 则B是A的子串,A为主串。B在A中出现了两次,其中首次出现所对应的主串位置是3。因此称B在A中的序号(或位置)为3 求子串: Status SubString(SString Sub, SString S, int pos, int len) { // 用Sub返回串S的第pos个字符起长度为len的子串。 //其中,1≤pos≤StrLength(S)且0≤len≤StrLength(S)-//pos+1 。 if ( pos1 || posS[0] || len0 || lenS[0]-pos+1 ) return ERROR; Sub[1..len] = S[pos..pos+len-1]; Sub[0] = len; return OK; }//SubString for ( i=S.length-1;i=pos-1; --1) //为插入T而腾出位置 S.ch[i+T.length] = S.ch[i]; S.ch[pos-1..po

文档评论(0)

1亿VIP精品文档

相关文档