// derniere-occurrence.c

// << Algorithmique du texte >>
// Maxime Crochemore, Christophe Hancart et Thierry Lecroq
// Vuibert, 2001.

#include <stdio.h>
#include "chl.h"


int *derniereOccurrence(Mot x, Longueur m) {
   Lettre a;
   int k;
   int *dernOcc;

   dernOcc = (int *)malloc(m * sizeof(int));
   if (dernOcc == NULL) error("derniereOccurrence");
   for (a = PREMIERELETTRE; a <= DERNIERELETTRE; ++a)
      dernOcc[a] = m;
   for (k = 0; k <= m - 2; ++k)
      dernOcc[x[k]] = m - 1 - k;
   return(dernOcc);
}