I have a list of 10 numbers in a array and want to sort them. Basically I am using a "quick sort" and want to swap 2 positions in a array. But Im stuck with the code for how to do this.
My code is written below. If anyone has any ideas, it would be a big help. The line I need is with the comment //help me towards the bottom.
CODE
====
#include <iostream>
#include <string>
#define MAX 10
using namespace std;
// declare a function to perform the sort
void qsort();
int array[MAX];
int lower, upper, PivotPos, PivotVal, f, b;
int lVal, temp;
// main program
void main()
{
// enter the numbers into the array
int x;
for(x=0; x<MAX; x++)
{
cout << "\nEnter a number ";
cin >> array[x];
}
// call the quick sort function to perform the sort on the global array
qsort();
// display the sorted list
int j;
for(j=0; j<MAX; j++)
{
cout << endl << array[j];
}
cout << endl << endl;
}
// end of program
void qsort()
{
PivotPos=lower;
PivotVal=array[lower];
b=upper;
f=lower+1;
if (upper==lower)
{ // do nothing
}
else
{
if (upper-1==lower)
{
if(array[upper]<array[lower])
{
// help me
}
}
else
{
while (f<b)
{
while (array[f]<PivotVal)
f++;
while (array[b]>PivotVal)
b--;
}
}
}
}