lastname 是记录中的一个字段,EmployeeRecord 在record.h 中定义,我正在尝试使用Qsort 对employee[emptotal].lastname 中的字符串进行排序。
#include "./record.h"
void externalSort(EmployeeRecord *lastname,int empcount,int emptotal)
{
empcount = 0;
emptotal = 5;
EmployeeRecord employee[emptotal];
int left=empcount,
right=emptotal;
EmployeeRecord pivot[].lastname = employee[(empcount+emptotal)/2].lastname;
while (left < right) {
// find left candidate
while (&employee[left].lastname < &pivot[(empcount+emptotal)/2].lastname) left++;
// find right candidate
while (&employee[right].lastname > &pivot[(empcount+emptotal)/2].lastname) right--;
if (left <= right) {
EmployeeRecord &temp.lastname = &employee[left].lastname;
&employee[left].lastname = &employee[right].lastname;
&employee[right].lastname = &temp.lastname;
left++;
right--;
}
} // while left < right
if (empcount < right) externalSort(char *lastname,empcount,right);
if (left < emptotal) externalSort(char *lastname,left,emptotal);
}
很抱歉有这么多不同的变化,我不知道前几行的正确方法,我的主要问题是声明行,EmployeeRecord pivot[].lastname = employee[(empcount +emptal)/2].姓氏;我相信,一旦我知道如何正确声明枢轴,我就会知道如何正确分配排序。
(也将有助于分配温度。)
(如果有帮助,请记录.h)
typedef char STR9[9+1];
typedef char STR7[7+1];
typedef char STR16[16+1];
typedef struct EmployeeRecord
{
STR9 lastname;
STR7 firstname;
STR16 fullname;
float hours,
overhours,
pay_rate,
defered,
gross,
fedtax,
statetax,
ssitax,
netpay;
} EmployeeRecord;