天津大学:《数据结构 Data Structures》课程PPT教学课件(英文版)Chapter 9 String

String (字符串) string is composed ofn(20) characters in an orderly sequence recorded as s:“c1c 1-2 S is string name 12-3·· C )y is value is a character n is string length。 Such as,S=“ Tsinghua University
String(字符串) string is composed of n( 0 ) characters in an orderly sequence. recorded as S : “c1 c2 c3…cn ” S is string name “ c1 c2 c3…cn” is value ci is a character n is string length。 Such as, S = “Tsinghua University

ADT and class definition of string const int maxLen=128: class string 3 int curlen: /的当前长度 char sch 的存储数组 public: String( const String ob ) String( const char x init ) String o; Strigoi delete[ ch; 3
const int maxLen = 128; class String { int curLen; //串的当前长度 char *ch; //串的存储数组 public: String ( const String& ob ); String ( const char * init ); String ( ); ~String ( ) { delete [ ] ch; } ADT and class definition of string

int Length const i return curLen; f /求当前串this的实际长度 String &operator(( int pos, int len ) /取thi从pos开始len个字符组成的子串 int operator =- const String &ob) ireturn strcmp(ch, ob.ch)=0;3 /判当前串*this与对象串ob是否相等 int operator !=( const String &ob const return strcmp(ch, ob.ch)!=0; 3 /判当前串ths与对象串ob是否不等
int Length ( ) const { return curLen; } //求当前串*this的实际长度 String &operator ( ) ( int pos, int len ); //取*this从pos开始len个字符组成的子串 int operator == ( const String &ob ) { return strcmp (ch, ob.ch) == 0; } //判当前串*this与对象串ob是否相等 int operator != ( const String &ob ) const { return strcmp (ch, ob.ch) != 0; } //判当前串*this与对象串ob是否不等

int operator ! o const i return curLen ==0; 5 /判当前串“this是否空串 String &operator =(String &ob); /将串ob赋给当前串*this String &operator +=(String &ob); /将串ob连接到当前串“ths之后 char &operator [ int 1); /取当前串“th的第i个字符 int Find( string &e pat ) const;
int operator ! ( ) const { return curLen == 0; } //判当前串*this是否空串 String &operator = (String &ob); //将串ob赋给当前串*this String &operator += (String &ob); //将串ob连接到当前串*this之后 char &operator [ ] ( int i ); //取当前串*this的第 i 个字符 int Find ( String& pat ) const; }

Implementation of strings basic operation String String( const String ob)t 复制构造函数:从已有串ob复制 ch= new charImaxLen+11;创刨建串数组 if ch==NULL cer<<“存储分配错!Ⅷm”; exit(1); curlen= ob. curlen;1复制串长度 Cpy(ch,obch);/复制串值 sti
String :: String ( const String& ob ) { //复制构造函数:从已有串ob复制 ch = new char[maxLen+1]; //创建串数组 if ( ch == NULL ) { cerr << “存储分配错! \n”; exit(1); } curLen = ob.curLen; //复制串长度 strcpy ( ch, ob.ch ); //复制串值 } Implementation of string’s basic operation

String String ( const char init )i 复制构造函数:从已有字符数组init复制 ch= new char maxLen+1];//创建串数组 if(ch== NULL cer<<“存储分配错!Ⅷm”; exit(D) curlen= strlen(init);//复制串长度 strcpy(cl , Init ); //复制串值
String :: String ( const char *init ) { //复制构造函数: 从已有字符数组*init复制 ch = new char[maxLen+1]; //创建串数组 if ( ch == NULL ){ cerr << “存储分配错 ! \n”; exit(1); } curLen = strlen ( init ); //复制串长度 strcpy ( ch, init ); //复制串值 }

String∷: String({ /构造函数:创建一个空串 ch= new char maxLen+1];/创建串数组 if(ch== NULL)t cer<<“存储分配错!n” exit(1); curlen =u ch|0]=“0
String :: String ( ) { //构造函数:创建一个空串 ch = new char[maxLen+1]; //创建串数组 if ( ch == NULL ) { cerr << “存储分配错!\n”; exit(1); } curLen = 0; ch[0] = ‘\0’; }

Algorithm of extracting substring pos=2, len=3 pos=5, len=4 in ty in finity 超出 posten -1 pos+ -1 curLen-l ≥ curlen
Algorithm of extracting substring pos+len -1 pos+len -1 curLen-1 curLen i n f i n i t y i n f i n i t y pos = 2, len = 3 pos = 5, len = 4 f i n i t y 超出

String& string operator((int pos, int len)( ∥从串中第pos个位置起连续提取len个字符 /形成子串返回 String* temp= new Strings;动态分配 if(pos≤0‖ posten-1>= maxlen‖lencurLen=0; /返回空串 temp->ch 0=0; eise /提是取子串 if( postlen-1>=curLen) len=curLen- pos;
String& String :: operator ( ) (int pos, int len) { //从串中第 pos 个位置起连续提取 len 个字符 //形成子串返回 String * temp = new String; //动态分配 if (pos= maxLen || lencurLen = 0; //返回空串 temp->ch[0] = '\0'; } else { //提取子串 if ( pos+len -1 >= curLen ) len = curLen - pos;

temp-> curlen=len;/子串长度 for (int i=0,j=pos; ichi=chj];传送串数组 temp-> chen]=“0,;子串结束 return x temp; example:st=“ university”,pos=3,len=4 use case: subSt=st (3, 4 substring extraction: subst=“vers
temp->curLen = len; //子串长度 for ( int i = 0, j = pos; i ch[i] = ch[j]; //传送串数组 temp->ch[len] = ‘\0’; //子串结束 } return * temp; } example:st = “university”, pos = 3, len = 4 use case: subSt = st (3, 4) substring extraction: subSt = “vers
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 天津大学:《数据结构 Data Structures》课程PPT教学课件(英文版)Chapter 8 Sorting.ppt
- 天津大学:《数据结构 Data Structures》课程PPT教学课件(英文版)Chapter 7 Search.ppt
- 天津大学:《数据结构 Data Structures》课程PPT教学课件(英文版)Chapter 6 Graph Algorithms.ppt
- 天津大学:《数据结构 Data Structures》课程PPT教学课件(英文版)Chapter 5 trees.ppt
- 天津大学:《数据结构 Data Structures》课程PPT教学课件(英文版)Chapter 4 Stacks Queues.ppt
- 天津大学:《数据结构 Data Structures》课程PPT教学课件(英文版)Chapter 3 Lists.ppt
- 天津大学:《数据结构 Data Structures》课程PPT教学课件(英文版)Chapter 2 Algorithm Analysis.ppt
- 天津大学:《数据结构 Data Structures》课程PPT教学课件(英文版)Chapter 10 The Disjoint Set ADT.ppt
- 成都理工大学工程技术学院:《C程序设计教程》第九章 变量的作用域与生存期.ppt
- 成都理工大学工程技术学院:《C程序设计教程》第八章 文件访问.ppt
- 成都理工大学工程技术学院:《C程序设计教程》第七章 结构体与共用体.ppt
- 成都理工大学工程技术学院:《C程序设计教程》第六章 函数.ppt
- 成都理工大学工程技术学院:《C程序设计教程》第五章 指针.ppt
- 成都理工大学工程技术学院:《C程序设计教程》第四章 数组.ppt
- 成都理工大学工程技术学院:《C程序设计教程》第三章 程序的控制结构.ppt
- 成都理工大学工程技术学院:《C程序设计教程》第二章 C程序设计基础.ppt
- 成都理工大学工程技术学院:《C程序设计教程》第一章 C程序概述.ppt
- 《vc++课件》类的设计和对象的使用.ppt
- 《vc++课件》c++基础2.ppt
- 《vc++课件》c++基础1.ppt
- 《C++程序设计》第十一讲 输出与输入.ppt
- 《C++程序设计》第二讲 C++语言基础.ppt
- 《C++程序设计》第九讲 派生与继承性.ppt
- 《C++程序设计》第六讲 类与对象.ppt
- 《C++程序设计》第七讲 类与对象.ppt
- 《C++程序设计》第三讲 C++语言基础.ppt
- 《C++程序设计》第十二讲 输出与输入.ppt
- 《C++程序设计》第十讲 虚函数与多态性.ppt
- 《C++程序设计》第八讲 类与对象.ppt
- 《C++程序设计》第四讲 C++语言基础.ppt
- 《C++程序设计》第五讲 类与对象.ppt
- 《C++程序设计》第一讲 面向对象程序设计.ppt
- 《10步之内学会 Photoshop CS》(英文版)Adobe® Photoshop® CS in 10 Simple Steps or Less.pdf
- 复旦大学:《数据通讯与计算机网络》课程教学资源(PPT课件)第一章 概论(高传善).ppt
- 复旦大学:《数据通讯与计算机网络》课程教学资源(PPT课件)第十章 网络管理基础和网络安全性 10.1 网络管理基础 10.2 数据加密.ppt
- 复旦大学:《数据通讯与计算机网络》课程教学资源(PPT课件)第十章 网络管理基础和网络安全性 10.3 网络安全.ppt
- 复旦大学:《数据通讯与计算机网络》课程教学资源(PPT课件)第二章 数据通信基础.ppt
- 复旦大学:《数据通讯与计算机网络》课程教学资源(PPT课件)第三章 数据链路层 3.1 差错检测与校正 3.2 数据链路层的功能.ppt
- 复旦大学:《数据通讯与计算机网络》课程教学资源(PPT课件)第三章 数据链路层 3.3 数据链路协议 3.4 协议描述与验证 3.5 链路通信规程举例.ppt
- 复旦大学:《数据通讯与计算机网络》课程教学资源(PPT课件)第四章 局域网和城域网(1/3).ppt