### Bubble Sort

I have my bubble sort working. I like to do an ascending followed by a descending sort. Any help would be well.. helpful
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include #include using namespace std; int i; int tmp; int array[50]; int n = 50; void Bubblesort(int array[], int n) { int tmp, j, q; for (q=0; q < n-1; q++) { for (j=0; j < n-1; j++) { if (array[j] < array[j+1])// changes acending to decending { tmp = array[j]; array[j] = array[j+1]; array[j+1] = tmp; } } } } int main() { for (int j = 0; j < n; j++) { i = rand() % 101; array[j] = i; } for (int k = 0; k < n; k++) { cout << array[k] << " "; } cout << endl << endl; Bubblesort(array, n); for (int i=0; i < n; i++) { cout << array[i] << " " ; } cout << endl; system("pause"); return 0; } ``````
If you have already sorted the array then all you need to do is reverse it.
Yeah, but what I am trying to do is output ascending followed by descending.
Yes you sort ascending, then you output it, then you reverse it (found this [untested] http://www.cplusplus.com/reference/algorithm/reverse/) and then you output it again.
Topic archived. No new replies allowed.