Set found to false.
Set position to -1.
Set index to 0.
While found is false and index < number of elements
If list[index] is equal to search value
found = true.
position = index.
End If
Add 1 to index.
End While.
Return position
#include <iostream>
using namespace std;
int main()
{
const int arraySize = 5;
int target;
// Array size and values already known.
int array[arraySize] = {1, 2, 3, 4, 5};
int first, mid, last;
cout << "Enter a target to be found: ";
cin >> target;
//search_program.cpp
/*
Set found to false.
Set position to -1.
Set index to 0.
While found is false and index < number of elements
If list[index] is equal to search value
found = true.
position = index.
End If
Add 1 to index.
End While.
Return position
*/
#include <iostream>
usingnamespace std;
int find(int search_value,int list[],intconst NUMBER_OF_ELEMENTS);
int main(){
intconst NUMBER_OF_ELEMENTS=5;
int list[NUMBER_OF_ELEMENTS]={1,2,3,4,5};
int key=3;
cout<<key<<" is in position: "<<find(key,list,NUMBER_OF_ELEMENTS)<<endl;
return 0; //indicates success
}//@end of main
int find(int search_value,int list[],intconst NUMBER_OF_ELEMENTS){
bool found=false; //Set found to false.
int position=-1; //Set position to -1
int index=0; //Set index to 0
while(found==false&&index<NUMBER_OF_ELEMENTS) //While found is false and index < number of elements
{
//If list[index] is equal to search value
// found = true.
//position = index.
// End If
//Add 1 to index.
}//end while
//????
}//end function find