this is the instruction:
//Prompt the user with this menu:
1. Linear Search
2. Binary Search
3. Exit
Item 1 is similar to Exercise 1's item 5. This time however, the linearSearch function must be implemented using recursion.
Item 2 is what we call the Binary Search. As discussed, the implementation of binarySearch is iterative. //
below is my code:
which needs a lot of help.
#include <iostream.h>
#include <conio.h>
//bool linearSearch(int[] ,int , int );
//bool binarySearch(int[],int x, int n);
void main(){
int choice, numbers[9], number ;
do{
cout<<"MENU:"<<endl;
cout<<"\t1.Linear Search\n\t2. Binary Search\n\t3. Exit\n";
cout<<"Enter your choice: ";
cin>>choice;
if (choice==1){
cout<<"Please enter 10 numbers: "<<endl;
for(int i=1;i<=10;i++)
cin>>numbers[9];
cout<<"Please enter 11th number: "<<endl;
cin>>number;
/* bool flag= linearSearch(numbers[],number,a);
if (flag==true){
cout<<"11th number is found in the previous ten numbers."<<endl;}
else if(flag==false){
cout<<"11th number is not found in the previous ten numbers."<<endl;}
}
*/
/* bool linearSearch(int nums[],int x, int n)
{
if(x==0); // size of the array
if(int nums[x-1]==n); // check if number in array is equal to 11th number
return true;
else
return linearSearch(int nums[],x-1,n); //goes to next number in array
else
return false;
}
*/
}
else if(choice==2){
cout<<"Please enter 10 numbers: "<<endl;
for(int i=1;i<=10;i++)
cin>>numbers[9];
cout<<"Please enter 11th number: "<<endl;
cin>>number;
/*bool binarySearch(int[9],int x, int n)
{*/
/*
lower=numbers[0];
upper=numbers[9];
mid= (lower+upper)/2;
while (lower!=upper)
*/
}
}
while (choice!=3);
}