here is what i need to do:
Generate 3 lists of 50000 random numbers between 0 and 10000.
Use the three sorting algorithms (Bubble, Selection, and Insertion) to sort the three lists. Code is in the lecture slides.
And print the median value of each algorithm.
Now I want you to use the time() class, to calculate how much time each of the three algorithms take.
You can do this by recording the time before and again after the sorting algorithm call. and then taking the difference between the two times.
Example:
time_t timeOne = time();
// call the sorting algorithm
time_t timeTwo = time();
// and calculate the difference, look up the function on the C++ reference page.
now answer these questions :
Which was the slowest sorting algorithm?
Why is it the slowest?
here is my code so far, where do i go from here:
CODE
#include <iostream>
#include <ctime>
using namespace std;
void bubblesort (int temp, int size);
int main (){
const int size = 50000;
int temp[size];
for(int i =0; i<size; i++){
temp[i]=rand()%10000;
cout << temp[i] << endl;
bubblesort (temp, size);
cout << temp[i];
return 0;
}
}
void bubblesort (int a[], int n) {
for (int i=1; i<n; i++)
for (int j=0; j<n-1; j++)
if (a[j]>a[j+1]);
}
void insertionsort (double list[], int arraysize){
for (int i=1; i<array size; i++) {
double currentelement = list[i];
int k;
for (k=i - 1; k>=0 && list[k]> currentelement; k--){
}
list [k + 1] = currentelement;
}
}
void selectionsort(int list[], int arraysize){
for(int i=0; i<arraysize; i++){
int min=list[i], index=i;
for(int j =i; j<arraysize; j++){
if(list[j]>min){
index=j;
min=list[j];
}
}
swap(&list[i], &list[index];
}
}