mirror of
https://git.freebsd.org/ports.git
synced 2025-04-29 18:16:48 -04:00
34 lines
592 B
C
34 lines
592 B
C
// simple example from README
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <divsufsort.h>
|
|
|
|
int main() {
|
|
// intput data
|
|
char *Text = "abracadabra";
|
|
int n = strlen(Text);
|
|
int i, j;
|
|
|
|
// allocate
|
|
int *SA = (int *)malloc(n * sizeof(int));
|
|
|
|
// sort
|
|
divsufsort((unsigned char *)Text, SA, n);
|
|
|
|
// output
|
|
for(i = 0; i < n; ++i) {
|
|
printf("SA[%2d] = %2d: ", i, SA[i]);
|
|
for(j = SA[i]; j < n; ++j) {
|
|
printf("%c", Text[j]);
|
|
}
|
|
printf("$\n");
|
|
}
|
|
|
|
// deallocate
|
|
free(SA);
|
|
|
|
return 0;
|
|
}
|