Greetings!
I've been messing around with a bit of code for a while now and I've got it compiling etc etc. The only problem is with perfecting the quicksort function (probably trivial, but then I'm not very skilled). From the output file, it seems to 'sort of' sort the string arrays that are fed in. I suspect the problem lies with the string compare function - which I'll admit I don't fully understand - but further fiddling has just given me a bunch of compilation errors.
Here is the quicksort, integrated to give some context (though if there's still too much unnecessary code, please tell me!):
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <fstream>
using namespace std;
struct employee {
char fname[20];
char sname[20];
int mnum;
};
void falphaquickSort (employee** a, int left, int right);// function declaration
int main(void){
employee* details = new employee[count];
employee** pdetails = new employee*[count];
for(int i=0; i < count; i++){// creates array (of structs to hold all persons in the file
in >> details[i].fname >> details[i].sname >> details[i].mnum;
}// etc etc. this part of the code works just fine.
delete [] details;
void falphaquickSort(employee** a, int left, int right) {
int i = left, j = right;
employee* tmp;
int pivot = (left + right)/2;
while(strcmp ((a[i])->fname, (a[pivot])->fname) < 0 ) {// start of partition. I'm told 'strcmp' gives a zero, -ve or +ve value depending on the relative values of the pointers but I'm stuck on how to utilise this to perfect the sort.
++i;
}
while(strcmp ((a[j])->fname, (a[pivot])->fname) > 0 ) {
--j;
}
if (i <= j) {
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
i++;
j--;
};// end of partition
if (left < j) // start of recursion
falphaquickSort(a, left, j);
if (i < right)
falphaquickSort(a, i, right);
}