Hi ,
I have an Assignment and I am not being able to do it by myself.
1) Write a program that obtains the execution time of Bubble sort, Selection sort, Insertion sort, and Quick sort for input size of 500,000, 1,000,000, 1,500,000, 2,000,000, 2,500,000, and 3,000,000. Print the results in a table.
2) Recursive Binary search , Write and implement a recursive version of the binary search algorithm and write a program to test it.
I have written this but I don`t know what the error is :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
using namespace std;
int binarySearch(const int list[], int length, const int & item);
int i=0;
int main()
{
int arr[10],size=10;
int x;
cout<<"Please enter the desired number"<<endl;
cin>>x;
cout<<"Please enter a sorted list of 10 numbers"<<endl;
while(i<10)
{
cin>>arr[i];
i++;
}
if(binarySearch(arr,size,x)==-1)
cout<<"Number is not in the list"<<endl;
else
cout<<"The index of the desired number is "<<binarySearch(arr,size,x)<<endl;
return 0;
}
int binarySearch(const int list[],int length,const int & item)
{
int first=0,last=length-1;
int mid;
bool found=false;
while (first<=last&&!found)
{
mid =(first+last)/2;
if (list[mid]==item)
found=true;
else if (list[mid]>item)
last=mid-1;
else
first=mid+1;
}
if (found)
return mid;
else if(first>last)
{
return -1;
}
else
return binarySearch(list,length,item);
}
|
Thank you for any help ...