You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
453 B
C++
20 lines
453 B
C++
void buildFail()
|
|
{
|
|
int h = 0, t = 0;
|
|
root->fail = &virt;
|
|
que[t++] = root;
|
|
while (h < t)
|
|
{
|
|
node *cur = que[h++];
|
|
for (int i = 0; i < 26; i++)
|
|
{
|
|
node *f = cur->fail;
|
|
while (f->trans[i] == 0) f = f->fail;
|
|
f = f->trans[i];
|
|
if (cur->trans[i])
|
|
(que[t++] = cur->trans[i])->fail = f;
|
|
else
|
|
cur->trans[i] = f;
|
|
}
|
|
}
|
|
} |