Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

3. Evaluate a Web-based training site.

Answered: 1 week ago