1. ## Help! With Sorting

Ok, So I got this assignment from my professor, and I know the first sections of code are correct, he pretty much gave them to us in class. But in the last section, section 5, I need to sory by decreasing order. He gave us a "hint" and said to sort by the number of astisks that are outputted, he also said to use the two sorting methos in the book selectionSort or Bubble sort. I think selection sort will work, but have no clue how to get it to work.

Code:
```#include<iostream>
#include<iomanip>
using namespace std;

const int size = 11;
int arx[size];

// if you want void printHist(); // Print histogram function (Sec. 2, 4, 6)
// void sortHist(); // Sort histogram function (Sec. 5)

void main()

// section 1-3
{
int i, j, temp;
srand(9876);

for (i=0; i<size; i++)
arx[i]=0;

for (i=0; i<2000; i++)
arx[rand()%11]++;

for (i=0; i<size; i++)
{
cout << arx[i] << ":" ;
for (j=0; j<arx[i]; j+=10)
cout<< "*" ;
cout << endl;
}

// Section 4
cout<<endl<<endl;
for (i=0; i<size; i++)
arx[i]=0;

for (i=0; i<2000; i++)
{
temp=((rand()%11) + (rand()%11))/2;
arx[temp]++;
}

for (i=0; i<size; i++)
{
cout << arx[i] << ":" ;
for (j=0; j<arx[i]; j+=10)
cout<< "*" ;
cout << endl;
}

//Section 5 Sort from greatest to least number of ****
cout<<endl<<endl;

for (i=0; i<size; i++)
arx[i]=0;

for (i=0; i<2000; i++)
{
temp=((rand()%11) + (rand()%11))/2;
arx[temp]++;
}

for (i=0; i<size; i++)
{
cout << arx[i] << ":" ;
for (j=0; j<arx[i]; j+=10)
cout<< "*" ;
cout << endl;
}
} // main```

Jessica

2. So once you've picked your sorting technique, implement it. You've got your data in arx[], and apparently you want it from high to low (so be sure as you follow along to switch less-than and greater-than, since most things sort from low to high). Hopefully you can figure out how to swap two numbers.

3. Bubble Sort for an array is pretty simple. For reference, here's the explanation including Pseudocode implementation code from Wikipedia. And, from a quick google, here's someone else's reasonable C++ implementation of it: simplified bubble sort c++ - C++ (Lines 25 to 43)

Happy Birthday for last week! I wonder if you like doing the same thing during thunderstorms that I do.

4. Thanks!

5. Couple nits:

#1
Code:
```const int size = 11;

...

for (i=0; i<2000; i++)
arx[rand()%11]++;

...

for (i=0; i<2000; i++)
{
temp=((rand()%11) + (rand()%11))/2;
arx[temp]++;
}

...

for (i=0; i<2000; i++)
{
temp=((rand()%11) + (rand()%11))/2;
arx[temp]++;
}```
You should be able to safely replace those "magic" numbers with the variable size. If that variable ever changes then you'd need to find and modify the code in several extra places. If you use the variable size instead and at some point in the future change its value, then there is nothing else that needs to be done with the code other than change size from 11 to something else.

#2
Code:
`void main()`
main should return int not void.