Question: The function contains() scans an array to determine if an item is in the array. The function returns true if the item found and false
The function contains() scans an array to determine if an item is in the array. The function returns true if the item found and false otherwise.
The following implementation works but is not a good solution.
bool contains(int arr[], int n, int item)
{
int i;
bool itemFound = false;
for (i = 0; i < n; i++)
if (arr[i] == item)
itemFound = true;
return itemFound;
}
What correction would make the code more efficient?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
