Question
Analyze the following program, which searches the array linearly to find a certain valve in the array. Go through the program and write a summary
Analyze the following program, which searches the array linearly to find a certain valve in the array. Go through the program and write a summary about the search procedure
// Linear search of an array
#include "stdafx.h"
#include
using namespace std;
int linearSearch( const int [], int, int );
int main()
{
const int arraySize = 100;
int a[ arraySize ], searchKey, element;
for ( int x = 0; x
a[ x ] = 2 * x;
cout
cin >> searchKey;
element = linearSearch( a, searchKey, arraySize );
if ( element != -1 )
cout
else
cout
return 0; }
int linearSearch( const int array[], int key, int sizeOfArray )
{
for ( int n = 0; n
if ( array[ n ] == key )
return n;
return -1; }
/ Linear search of an arrav #include "stdats +' #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started