-
Linear search
hi guyz, i am working on this c++ assignment:
1. Linear Search
I made this function and it goes through a list of int values but i want to modify it so that it goes through all the names and returns the name found. Plz help me out guyz
Code:
int searchList(int list[], int numElems, int value)
{
int index = 0; // Used as a subscript to search array
int position = -1; // To record position of search value
bool found = false; // Flag to indicate if value was found
while (index < numElems && !found)
{
if (list[index] == value) // If the value is found
{
found = true; // Set the flag
position = index; // Record the value's subscript
}
index++; // Go to the next element
}
return position; // Return the position, or -1
this is wat i have so far!
i was missing the following info:
File for names and marks:
Collins Bill 80
Smith Bart 75
Allen Jim 82
Griffin Jim 55
Stamey Marty 90
Rose Geri 78
Taylor Terri 56
Johnson Jill 77
Allison Jeff 45
Looney Joe 89
Wolfe Bill 63
James Jean 72
Weaver Jim 77
Pore Bob 91
Rutherford Greg 42
Javens Renee 74
Harrison Rose 58
Setzer Cathy 93
Pike Gordon 48
Holland Beth 79