Question: Exercise 3: Sorting (10 points) void mysort(int a[], int len); Write a function called mysort that rearranges elements of an array a so that they

Exercise 3: Sorting (10 points)

void mysort(int a[], int len);

Write a function called mysort that rearranges elements of an array a so that they form an increasing sequence of values. Allow for different array positions to contain the same value.

Develop your own sorting algorithm; do not use a predefined sort routine from the standard library.

Implement a simple sorting algorithm rather than an efficient algorithm.

please use the bubble sort and the main function.

here is what I came up with:

#include #include using namespace std; void mysort(int a[], int len){ for (int i= 0; i < len-1; i++){ for (int j = 0; j < len-i-1; j++) if (a[j] > a[j+1]) { int temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } }

int main (){ int a[8] = {19, 5, 77, 101, 43, 76, 19, 8}; cout << "Sorted values: " << mysort(a, 8)<< endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!