lastname是record.h中定義的EmployeeRecord中的字段,我試圖使用 Qsort對employee [emptotal] .lastname中的字符串進行排序。在cs或C++中使用Qsort中的記錄數組
#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支點[] .lastname = employee [(empcount + emptotal)/ 2] .lastname; 一旦我知道如何正確聲明數據透視表,那麼我會知道如何正確地分配排序,我相信。
(也將幫助分配溫度)
(record.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;
你應該使用'STRCMP(員工[左] .lastname,pivot [(empcount + emptotal)/ 2] .lastname)<0'而不是'&employee [left] .lastname <&pivot [(empcount + emptotal)/ 2] .lastname' – higuaro
所以不是我的原始問題,但感謝您的建議。 –