// bon-suffixe.c // << Algorithmique du texte >> // Maxime Crochemore, Christophe Hancart et Thierry Lecroq // Vuibert, 2001. #include <stdio.h> #include "chl.h" int *bonSuffixe(Mot x, Longueur m, int suff[]) { int i, j, *bonSuff; bonSuff = (int *)malloc(m*sizeof(int)); if (bonSuff == NULL) error("bonSuffixe"); j = 0; for (i = m - 2; i >= -1; --i) if (i == -1 || suff[i] == i + 1) while (j < m - 1 - i) { bonSuff[j] = m - 1 - i; ++j; } for (i = 0; i <= m - 2; ++i) bonSuff[m - 1 - suff[i]] = m - 1 - i; return(bonSuff); }