Skip to content

Instantly share code, notes, and snippets.

@zcwang
Created March 30, 2018 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zcwang/cece6997fb94b586da844ac3a266e763 to your computer and use it in GitHub Desktop.
Save zcwang/cece6997fb94b586da844ac3a266e763 to your computer and use it in GitHub Desktop.
For finding common element in three arrays
#define FOUND 1
#define NOT_FOUND 0
int search(int x[], int y[], int z[], int X, int Y, int Z,
int *XX, int *YY, int *ZZ) {
*XX = *YY = *ZZ = 0;
while (*XX < X && *YY < Y && *ZZ < Z)
if (x[*XX] < y[*YY]) {
(*XX)++;
} else if (y[*YY] < z[*ZZ]) {
(*YY)++;
} else if (z[*ZZ] < x[*XX]) {
(*ZZ)++;
} else {
return FOUND;
}
return NOT_FOUND;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment