Created
March 30, 2018 06:26
-
-
Save zcwang/cece6997fb94b586da844ac3a266e763 to your computer and use it in GitHub Desktop.
For finding common element in three arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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