I'm trying to sort the values in the array "tab" using quicksort, but it isn't working. the main function just set names and salaries for each tab[n]
typedef struct employee Employee;
struct employee{
char name[81];
float salary;
};
Employee *tab[10];
void sort(Employee **tab, int begin, int end){
int p = tab[(begin + end) / 2] , i = end, j = begin;
/*p is the pivot*/
do{
while(tab[i]->salary < p && i < end) i++;
while(tab[j]->salary > p && j > begin) j--;
if(i <= j){
int tmp = tab[i]->salary;
tab[i]->salary = tab[j]->salary;
tab[j]->salary = tmp;
i++; j--;
}
}while(i <= j);
if(begin < j) sort(tab, begin, j);
if(end > i) sort(tab, i, end);
}
pisEmployee*, notintEmployeestructure looking like? Why are you only swapping salaries and not the whole employee records? The person whose name comes first ends up with the lowest salary, ad the person whose name comes last ends up with the highest salary? Or vice versa?src/scriptsdirectory. This one issscce. I work on Macs mostly, sosscce | sed 5q | pbcopygives me the text quoted above in the paste buffer, and command-V (⌘-V) puts it into the comment. The other links in lines 6+ are: See also How to Ask Questions the Smart Way and Writing the perfect question