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 : #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); } Code (markup): Thank you for any help provided.
I could do that fairly easily for you but I have to agree with sarahk. Why take the class and not learn the language?
It doesn't matter now - .h issue the new namespace std standard doesn't need a .h extension to iostream and other header files. And like others have pointed out, its better if you do your assignment your self. Study, research and then write the code your self. A google search often helps : I came up with : http://www.daniweb.com/forums/thread19231.html