#include #include #include #include const char *mary="Mary"; const char *bob="Bob"; const char *jim="Jim"; const char *john="John"; const char *serena="Serena"; const char *setA[] = {john,bob,mary,serena}; const char *setB[] = {jim,mary,john,bob}; #define XSET(j) j, (sizeof(j)/sizeof(*j)) #define TALLOC(n,typ) malloc(n*sizeof(typ)) typedef enum { esdDIFFERENCE, esdSYMMETRIC } EsdFunction; /** * * * * * * * * * * * * * * * * * * * * * return value is difference or symmetric difference set * its size is returned in sym_size * f determinse whether it is a symmetric difference, or normal difference * * * * * * * * * * * * * * * * * * * * **/ const char ** symmdiff( int *sym_size, EsdFunction f, const char *setA[], int setAsize, const char *setB[], int setBsize) { int union_size; int max_union_size; int diff_size; const char **union_set; const char **diff_set; int *union_xor; int ix, ixu; max_union_size = setAsize + setBsize; union_set = TALLOC(max_union_size, const char *); union_xor = TALLOC(max_union_size, int); /* I'm assuming here that setA has no duplicates, * i.e. is a set in mathematical sense */ for (ix=0; ix0; i--) { e = list[i]; for (j = i-1; j>=0; j--) { if (strcmp(list[j], e) == 0) { return 0; } } } return 1; } void printSet (const char *set[], int ssize) { int ix; printf(" = {"); for (ix=0;ix