Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 3: Functions or classes are ok. Create an array that holds 1000 random floats between 1-1000. Implement Merge Sort to sort the values in
Task 3:
Functions or classes are ok.
Create an array that holds 1000 random floats between 1-1000.
Implement Merge Sort to sort the values in ascending order. Least Greatest
Measure the time it takes to execute the sort in milliseconds or even nanoseconds.
Please run the sort 3 times.
-
Attach Photos of Source Code and Output-----
-
---------------------------------------------------------------------------Here is the code Implement Selection Sort to sort the values in ascending order. Least Greatest
-
#include
#include #include using namespace std; void swap(float *xp, float *yp) { float temp = *xp; *xp = *yp; *yp = temp; } void SortingSelection(float arr[], int n) { //clock to check time int i, j, min_idx; // One by one move boundary of unsorted subarray for (i = 0; i < n-1; i++) { // Find the minimum element in unsorted array min_idx = i; for (j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; // Swap the found minimum element with the first element swap(&arr[min_idx], &arr[i]); } } int main() { // your code goes here int size = 1000; float arr[size]; int i=0; int high = 1000; srand(time(0)); for(i=0;i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started