/* Demonstration of linear search algorithm used to find
a student's grade from a set of grade records. The key
for the search is the student's I.D. number.
*/
#include
#include
#define MAXSTUDENTS 50 /* Constant */
/* linear Function Declaration */
int linear(long int id[], long int key, int n)
{
/* Simple linear search - check all the elements of the
array for a match starting at zero until a match is found.
On average, the function will make n/2 comparisons.
If no match is found, a not-found flag is returned, otherwise
the function returns the correct subscript for the student record
*/
int i, flag;
flag = -1;
for( i=0; iMAXSTUDENTS );
printf("Enter students' names and grades\n");
printf("in this format ->Name:Doe,John[ENTER] (no spaces)\n");
printf(" ->ID #:9421234[ENTER]\n");
for( i=0; i