The concept of a string what is a string?
String: A finite sequence consisting of 0 or more characters. Recorded as: s= ' a1a2...an ' (n≥0)
S is a string name, ' A1a2...an ' is a string value, and n is the length of a string.
The position of a substring in the main string: represented by the position of the first character of the substring in the main string.
String equivalence: When and only if the string values of the two strings are equal (the lengths of the two strings are equal, and the corresponding characters are equal
Data type of the string
ADT String { D={ ai |ai∈CharacterSet, i=1,2,...,n, n≥0 } R={ < ai-1, ai > | ai-1, ai ∈D, i=2,...,n } 基本操作:……}
Where D is the data object R is the data relationship
String is a finite-length sequence of characters, enclosed by a pair of single quotes, such as: "A string"
A string of operations
intIndex (String S, String T,int POS) {if(POS>0) {n = strlength (S);m= Strlength (T); i =POS; while(I <= Nm+1) {SubString ( Sub, S, I, m); if(Strcompare ( Sub, T)! = 0) ++i; Else returnI } }return 0; }
If return 0 means that there is no substring equal to T in S
T is a non-empty string. Returns the position of the first such substring in S if there is a substring equal to T after the POS character in the main string s, otherwise returns 0
Example of a string operation (*)
1. Substring substring (&sub,s,pos,len)
SubString (Sub, "Commander", 4, 3)
Get sub =?
' Man '
Take 3 elements starting from the 4th element of "Commander"
SubString (Sub,? Commander?, 1, 9)
Get sub =?
' Commander '
Take 9 elements starting from the 1th element of "commander"
SubString (Sub, "Commander", 9, 1)
Get sub =?
' R '
Take 1 elements starting from the 9th element of "Commander"
SubString (Sub,? Commander?, 4, 7)
Get sub =?
' Mander '
SubString (Sub, "Beijing, 7, 2)
Get sub =?
' G '
Take 1 elements starting from the 9th element of "Commander"
SubString (Sub, "Student", 5, 0)
Get sub =?
’ ‘
Summarize
The logical structure of a string is very similar to a linear table, except that the data object of a string is constrained to a character set
The basic operation of the string and the linear table are very different:
1. In the basic operation of the linear table, most of the "single element" as the object of operation
2. In the basic operation of a string, the "whole of string" is usually used as the object of operation.
Data structure-the nature and basic operation of the string (i)