数据结构英文课件:Chap4 String

上传人:新** 文档编号:592297639 上传时间:2024-09-20 格式:PPT 页数:12 大小:395.50KB
返回 下载 相关 举报
数据结构英文课件:Chap4 String_第1页
第1页 / 共12页
数据结构英文课件:Chap4 String_第2页
第2页 / 共12页
数据结构英文课件:Chap4 String_第3页
第3页 / 共12页
数据结构英文课件:Chap4 String_第4页
第4页 / 共12页
数据结构英文课件:Chap4 String_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《数据结构英文课件:Chap4 String》由会员分享,可在线阅读,更多相关《数据结构英文课件:Chap4 String(12页珍藏版)》请在金锄头文库上搜索。

1、Chap4 StringOverviewStringImplementation of StringBasic operationsStrings pattern matching algorithmStringString is a character sequence composing zero or several characters;Strings general form is: s=“s1s2s3sn”;si(1in) is a random character called the element of the string, i is sis position number

2、 in the whole string;We call the special string of size 0 is an empty string, marked by .StringWe call any sub-sequence composing of several consecutive characters a substring;The position of a substring in the whole string is the position of its first characters position in the whole string;When tw

3、o strings have equal size and the same character in the corresponding position, we deem the two strings are equal.Implementation of StringArray Implementation 1 #define MAXSIZE 256 typedef struct char SMAXSIZE; int curlen; SeqString;Implementation of StringArray Implementation 2 The string is ended

4、up by a specific character 0. Implementation of StringLinked List Implementation The string is stored into a single linked list. Though it is feasible, it will bring space waste. So we sometimes store a substring in one node of the linked list, its called block-storage. Basic OperationsStrLength(s):

5、 returns the length of the stringStrAssign(s1, s2): copy s2 to s1StrConcat(s1, s2): connect s2 in the end of s1SubStr(s, i, len): get a substring of size len from the position i of sCmpStr(s1, s2): compare two strings s1, s2StrIndex(s, t): find the position of string t in the string s Basic Operatio

6、nsStrInsert(s, i, t): insert t into s on the position i of tStrDelete(s, i, len): delete a substring of size len from the position of string sStrRep(s, t, r): replace any string t appeared in the string s by string r Pattern MatchingStrings pattern matching is a very important string operation;The p

7、rocedure of finding substring t in the given string s is called pattern matching;When found, the routine returns the first matching position. If not found, returns 0. Example 4.1Simple pattern matching algorithmint StrIndex_BFint StrIndex_BF(char *s, char *t)(char *s, char *t) int i=1,j=1; int i=1,j=1; while (i=s0 & j=t0 ) while (i=s0 & jt0) if (jt0) return (i-t0); return (i-t0); else else return 0; return 0;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 研究生课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号