Search Benchmarks

Write a program that has an array of at least 20 integers. It should call
a function that uses the linear search algorithm to locate one
of the values. The function should keep a count of the number of
comparisons it makes until it finds the value. The program then should
call a function that uses the binary search algorithm to locate the
same value. It should also keep count of the number of comparisons it makes. Display these values on the screen.

so far this is what I have
/*
search benchmark.cpp
this program searchs through a array of 20 integers
*/

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int array [20];
int count;
int number;
int counta;
int countb;

int main ()
{
int array [20] = {9, 18, 27, 36, 54, 45, 99, 63, 108, 72, 3, 6, 12, 15, 21, 24, 30, 33, 39, 42};
cout << " please pick one of the following numbers to search for" << endl;
for (count = 0, count ++, count [20]);
{
<<array[count] << "" << endl;
count = count +1;
}

cin >> number;
int linearsearch (number [], count = 0, count ++);
{
counta = counta+1;
if number = array{count}
{
cout << "the number is in memory position " << count << endl;
cout << "it took " << count << "passes to find it" << endl;
}
else
{
cout " the number is not in memory position " << count << endl;
}


cout <<"the numbers in ascending order are :" << endl;









}
Last edited on
Topic archived. No new replies allowed.