Well dude, I'm gonna be completely honest here and say that I attempted to write my own version of the code that would sort the array and it really (excuse my language) f***** my head over.
So good luck with that.
However what I can offer you is a more user friendly way of entering the array elements, what it does is take in the elements of the array and prints them out. After that (the sorting), I'm not sure. Good luck to you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include<iostream>
using namespace std;
int main() {
int certainarray[20] = {0};
int noelements = 0;
int element = 0;
int noarray = 0;
cout << "Enter no. of elements you would like to insert into the array (max is 20)." << endl;
cin >> noelements;
cout << "Please enter the elements of your array in consecutive order (integers only)." << endl;
while (true) {
if (cin >> element) {
certainarray[noarray] = element;
noarray++;}
if (noarray == noelements) {
break;}}
cout << "The current elements of your array are: ";
for (int i = 0; i < noelements; i++){
cout << certainarray[i] << " ";}
while (true) {}
return 0;}
|
Ah, I think I found a problem, the function is call-by-value, so it won't actually change the elements of the array I believe. I think you should start from scratch and maybe use a bunch of nested while or for loops instead to change the array.
I suggest creating a new array based on the old array. And then printing a new array.
Cuz when I pasted in your qsort it said b[/*whatever is in here*/] in the function definition was an undeclared identifier or something (I think), even though I changed my array up top to b[20], so it may be that the function was looking for a local array called b[/*whatever is in here*/], instead of the global b.
I don't know, I may be wrong.