Implementation of sequential strings
The data structure of the sequence string is as follows:
typedef struct{ElemType data[MaxSize];int length;}SqString;
Implement the following functions:
Void StrAssign (SqString * & s, char str []); // assign a value to an ordered string to initialize void StrCopy (SqString * & s, SqString * t ); // string copy int StrEqual (SqString * s, SqString * t); // whether the two strings are equal int StrLength (SqString * s ); // The string is equal to void Concat (SqString * & s, SqString * t); // the string is connected to SqString SubStr (SqString * s, int I, int j ); // obtain the substring SqString InsStr (SqString s1, int I, SqString s2); // Insert the string SqString DelStr (SqString s, int I, int j ); // Delete the string SqString RepStr (SqString s, int I, int j, SqString t); // Replace the string void DispStr (SqString * s); // output the string
Specific implementation code:
# Include
# Include
# Include
# Define MaxSize 10000 # define ElemType char # define GET_ARRAY_LENGTH (array) (sizeof (array)/sizeof (array [0]) using namespace std; typedef struct {ElemType data [MaxSize]; int length;} SqString; void StrAssign (SqString * & s, char str []); // assign a value to an ordered string to initialize void StrCopy (SqString * & s, SqString * t); // copy the string to int StrEqual (SqString * s, SqString * t ); // whether the two strings are equal int StrLength (SqString * s); // whether the strings are equal void Concat (SqString * & s, Sq String * t); // String connection SqString SubStr (SqString * s, int I, int j); // obtain the substring SqString InsStr (SqString s1, int I, SqString s2 ); // Insert the string SqString DelStr (SqString s, int I, int j); // Delete the string SqString RepStr (SqString s, int I, int j, SqString t ); // Replace the string void DispStr (SqString * s); // output string void StrAssign (SqString & s, char str []) {int I = 0; while (str [I]! = '\ 0') {s. data [I] = str [I]; I ++;} s. length = I;} void StrCopy (SqString & s, SqString t) {int I = 0; while (t. data [I]! = '\ 0') {s. data [I] = t. data [I]; I ++;} s. length = t. length;} int StrEqual (SqString s, SqString t) {int flag = 0; if (s. length! = T. length) return flag; else {for (int I = 0; I
S. length | I + j> s. length + 1) return str; for (int k = 0; k
S1.length + 1) return str; for (int m = 0; m
S. length | j <0 | I + j> s. length + 1) return str; for (int k = 0; k
S. length + 1) return str; for (int k = 0; k