Skip to content

Instantly share code, notes, and snippets.

@obstschale
Created June 30, 2012 18:49
Show Gist options
  • Save obstschale/3025082 to your computer and use it in GitHub Desktop.
Save obstschale/3025082 to your computer and use it in GitHub Desktop.
Linear Search
int linearSearch(char *list[ ], char target[ ], int n)‏
{
int i;
for (i = 0; i < n; i++)‏
{
if (strcmp(target, list[i]) == 0)‏
{
return i;
}
} // end for
return -1;
} // end linear search
@obstschale
Copy link
Author

returns index of target string in the given list,
Or returns -1 if target string is not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment