数据结构英文版课件Chapter2.String and Character Manipulation

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

理学院 物理系
(6) Insert
2.String and Character Manipulation
(a) the inserted position of the original string oristr is p; (b) set the size of target string tarstr to be the length =original length +length of the inserted string insstr; (c) extract the characters of the original string up to the position p-1, and store it the in target string; (d) insert the string insstr; (e) extract the remaining characters from position p; placed it at the end of the target string;
2010-3-30 Data Structures Using C C Data Structures Using 3/30/2010 3/30/2010
2.String and Character Manipulation
5/30 5
C. X. Deng
7.1 Quadrature squeezing
#Example: char str[10],str1[10], str2[10]; Search: str1=“ing”; Test in: str=“Strings”; Searching: ing Searching: ing TRUE no match Strip FALSE
3/30/2010 3/30/2010 7/30 7
Data Structures Using C C Data Structures Using
C. X. Deng
7.1 Quadrature squeezing
理学院 物理系
(6) Delete
(a) Accept the substring delstr to be deleted from the original string oristr; (b) Checking whether delstr is in oristr; (c) set p is the starting position of the match of the substring delstr; (d) find the length L of the substring delstr; (e) Place the first p-1 characters from the original string in the target string tarstr; (f) extract the remaining characters starting from the position (p+1) in the original string oristr and place it at the end of the target string tarstr; #Example: char oristr[20], tarstr[10]; oristr=“Bed of Roses”; deleted position: p=4 tarstr=“Bed”; length: 9
#Example: char oristr[10], insstr[4], tarstr[20]; oristr=“Bed Roses”; insstr=“of ”; tarstr=“Bed of Roses”;
2010-3-30
inserted position: p=5
3/30/2010 3/30/2010 9/30 9
2010-3-30
Data Structures Using C C Data Structures Using
3/30/2010 3/30/2010
4/30 4
C. X. Deng
7.1 Quadrature squeezing
理学院 物理系
◆ Methods of the on Strings
(1) Create (a) construct a respresentation of a string; (b) retain the value of a string in a variable. #Example: char str[20]; if str=“South China”; (2) Concatenation #Example: char str1[10], str2[10], str[20]; if str1=“South ”; if str2=“China”; str=“South China”;
#Example: char str[10],str1[10], str2[10]; Search: str1=“ing”; Searching: ing in: str=“String”; match Replace: str2=“ong”; String str1=“Strong”; Replace: ong
2010-3-30 Data Structures Using C C Data Structures Using 3/30/2010 3/30/2010 3/30 3
C. X. Deng
7.1 Quadrature squeezing
理学院 物理系
2.2 Primitive Functions Of Operations on Strings
理学院 物理系
2.String and Character (3) Search and Replace Manipulation (a) a given string is searched in the string from first character to the last; (b) if a match is found, remove it; (c) save the position of the match; (d) a new string is inserted at the position of the match.
C. X. Deng
7.1 Quadrature squeezing
理学院 物理系
Data Structures Using C
Nicklaus Wirth:
2010-3-30
Data Structures Using C C Data Structures Using
3/30/2010 3/30/2010
2.String and Character Manipulation
(1)Create a string of text; (2)Concatenate two strings to form a third string; (3)Search and replace a given substring within a string; (4)Test for the identity of a string; (5)Compute the length of a string; (6)Insertion of a word within a string; (7)Deletion a word from a string.
◆ Alphabet: An alphabet is a symbol from the set V, where V is an finite nonempty set of symbols. Alphabet∈V,V={symbol}. #Examples: 2, ‘s’, ‘ ‘ ◆ String: An string is a sequence of characters or symbols. It is a concatenation of characters from the set V. String∈S, S={c1c2…}, ci∈V, V={symbol}. #Examples: “scut”, “2”,“s”
1/30 1
C. X. Deng
7.1 Quadrature squeezing
理学院 物理系
2. String and Character Manipulation
◆ Introduction ◆ Primitive Functions of Operations on Strings ◆ Representation of String ◆ String Manipulation in C ◆ Strings Manipulation Application
2010-3-30 Data Structures Using C C Data Structures Using 3/30/2010 3/30/2010
2.String and Character Manipulation
10/30 10
C. X. Deng
7.1 Quadrature squeezing
2010-3-30 Data Structures Using C C Data Structures Using 3/30/2010 3/30/2010 6/30 6
C. X. Deng
7.1 Quadrature squeezing
理学院 物理系
2.String and Character (4) Test for the identity Manipulation (a) a given substring is searched in the string on a character-by-character from first character to the last; (b) if a match is found, TRUE is return otherwise FALSE is returned.
2010-3-30
Data Structures Using C C Data Structures Using
3/30/2010 3/30/2010
2/30 2
C. X. Deng
7.1 Quadrature squeezing
理学院 物理系
2.1 Introduction
2.String and Character Manipulation
Strings
2010-3-30
match
Data Structures Using C C Data Structures Using
C. X. Deng
7.1 Quadrature squeezing
理学院 物理系
(5) Computing the length (a) initialize length=0; (b) pointing the cursor to the first character; (c) if the cursor is at the end of the string, output the length result, else do: (i) length=length+1; (ii) move the cursor to the next character; (d) repeat step (c). #Example: char str[10]; if str1=“Raman”; length=5;
理学院 物理系
2.3 Representation of String
(1) Fixed length string method
2010-3-30 Data Structures Using C C Data Structures Using 3/30/2010 3/30/2010
2.String and Character Manipulatiቤተ መጻሕፍቲ ባይዱn
8/30 8
C. X. Deng
7.1 Quadrature squeezing
相关文档
最新文档