早教吧 育儿知识 作业答案 考试题库 百科 知识分享

ImplementYourOwnStringClassUsingKMPTaskYourtaskissupposedtowriteastringclassofyourown.Andyourimplementationshouldatleastprovidethefollowingfunctions:string&insert(sizetpos1,conststring&str);Insertsacopyoftheent

题目详情
Implement Your Own String Class Using KMP
Task
Your task is supposed to write a string class of your own.And your implementation should at least provide the following functions:
string& insert ( size_t pos1,const string& str );
Inserts a copy of the entire string object str at character position pos1.
string& insert ( size_t pos1,const char * s,size_t n );
Inserts at the character position pos1,a copy of the string formed by the first n characters in the array of characters pointed by s.
string& erase ( size_t pos = 0,size_t n = npos );
Erases a sequence of n characters starting at position pos.Notice that both parameters are optional:with only one argument,the function deletes everything from position pos forwards,and with no arguments,the function deletes the entire string.
string& replace ( size_t pos1,size_t n1,const string& str );
The section,which begins at character position pos1 and spans for n1 characters within the string is replaced by a copy of the entire string object str.
string& replace ( size_t pos1,size_t n1,const char * s,size_t n2 );
The section,which begins at character position pos1 and spans for n1 characters within the string is replaced by a copy of the first n2 characters in the array of characters pointed by s.
void swap ( string& str );
Swaps the contents of the string with those of string object str,such that after the call to this member function,the contents of this string are those which were in str before the call,and the contents of str are those which were in this string.
string& operator+= ( const string& str );
string& operator+= ( const char* s );
Appends a copy of the argument to the string.
Find content in string
Searches the string for the content specified in either str,s or c,and returns the position of the first occurrence in the string.
size_t find ( const string& str,size_t pos = 0 ) const;
str string to be searched for in the object.The entire content of str must be matched in some part of the string to be considered a match.
pos Position of the first character in the string to be taken into consideration for possible matches.A value of 0 means that the entire string is considered.
size_t find ( const char* s,size_t pos,size_t n ) const;
s Array with a sequence of characters.
pos Position of the first character in the string to be taken into consideration for possible matches.A value of 0 means that the entire string is considered.
n Length of sequence of characters to search for,in other words only the first n characters of array s should be considered.
Finally,your main function is supposed to test all of the function of your implementation.
▼优质解答
答案和解析
你想表达什么,是关于kmp模式匹配的英文算法描述吗!
中文的早看懂了.