C++ program: In Computer Science, it is often very important to be able to locat
ID: 3569135 • Letter: C
Question
C++ program:
In Computer Science, it is often very important to be able to locate a specific data item inside a
list or collection of data. Algorithms that perform this function are called searching algorithms,
and there are many of these types of algorithms in Computer Science.
Although it is inefficient, one of the most common searching algorithms is called Linear Search.
In Linear Search we have a set of data that serves as the standard, usually stored within an array,
and a separate value that we are searching for within that data set. We
Explanation / Answer
int searchList(int stdList [], int numElems, int value)
{
int result;
bool isFound;
for(int i = 0; i < numElems; i++)
{
if(stdList[i] == value)
{
result = i;
isFound = true;
}
}
if(isFound)
return result;
else
return -1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.