The automatic machine matching algorithm is usually represented by a linked list. arrays are used here, which takes up a lot of space,
Have time to elaborate
# Include <iostream> <br/> using namespace STD; </P> <p> const int alphabet_len = 128; </P> <p> // construct an automation <br/>/* int */void preauto (int * automation, const char * pattern, const int pattern_len) <br/> {<br/> // int state = 0; <br/> for (INT I = 0; I <pattern_len; I ++) {<br/> int reserve = automation [I * alphabet_len + pattern [I]; <br/> automation [I * alphabet_len + pattern [I] = I + 1; <br/> memcpy (automation + (I + 1) * alphabet_len, automation + reserve * alphabet_len, alphabet_len * sizeof (INT )); <br/>}</P> <p> int DFA (const char * Text, const int text_len, const char * pattern, const int pattern_len) <br/> {<br/> // allocate memory for automation <br/> int * automation = new int [(pattern_len + 1) * alphabet_len]; <br/> // initialization <br/> for (INT I = 0; I <(pattern_len + 1) * alphabet_len; I ++) {<br/> automation [I] = 0; <br/>}< br/> // preprocessing <br/> preauto (automation, pattern, pattern_len ); </P> <p> int result =-1; <br/> // searching <br/> int auto_state = 0; <br/> for (INT I = 0; I <text_len; I ++) {<br/> auto_state = automation [auto_state * alphabet_len + Text [I]; <br/> If (auto_state = pattern_len) {<br/> result = i-pattern_len + 1; <br/> break; <br/>}</P> <p> Delete [] automation; <br/> return result; <br/>}