Must be written in C++. Write the function prototype and the function definition
ID: 3762876 • Letter: M
Question
Must be written in C++. Write the function prototype and the function definition to a linear search of an array. The function will accept three constant parameters: an integer array, an integers for the arrays size, and an integer for the element to search for. This function will return the index of the searched element, -1 otherwise. Must be written in C++. Write the function prototype and the function definition to a linear search of an array. The function will accept three constant parameters: an integer array, an integers for the arrays size, and an integer for the element to search for. This function will return the index of the searched element, -1 otherwise.Explanation / Answer
int linearSearch(const int [], const int, const int);
int linearSearch(const int arr[], const int arrSize, const int searchData) {
for (int i=0; i<arrSize; i++) {
if (arr[i] == searchData) {
return i;
}
}
return -1;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.