i need to write a program that will generate 50000 random number from 1-10000 and then sort them using three different functions. Bubble Sort, Insertion Sort, and Selective Sort
here is the code i have right now. i pretty much have the foundation layed out .. i think at least. i just need to tweak it to get it to work properly
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]; } }



LinkBack URL
About LinkBacks


