I am referring you to a previous link that compares the performance of qsort vs stdsort。比較qsort和std :: sort
我寫了一個C程序,填充一個大的std::map
,我想排序數組。我目前使用qsort
。
typedef std::map<uint16_t, uint32_t> TSrcMap;
TPSrcMap sp;
TSrcMap::iterator its;
/*Code to populate the array_start.*/
/*Code to populate the array_end.*/
typedef struct port_count
{
uint32_t port_number;
uint32_t port_count;
}port_count_t;
port_count_t pcount[10];
memset(pcount,0,sizeof(pcount));
size_t structs_len = sizeof(pcount)/sizeof(port_count_t);
for(its = stcp.begin(); its != stcp.end();its++)
{
if(pcount[smallest_index].port_count < (*its).second)
{
pcount[smallest_index].port_count = (*its).second;
pcount[smallest_index].port_number = (*its).first;
/*qsort(pcount, structs_len, sizeof(port_count_t), struct_cmp_by_port_count);*/
std::sort(pcount,sizeof(port_count_t));
}
}
qsort
函數正確地對數組進行排序。我想的qsort
性能與std::sort
但呼叫std::sort
通話是給編譯錯誤
呼叫沒有匹配功能
‘sort(port_count_t [10], long unsigned int)’
比較,我想的std::sort
性能與qsort
比較算法。我怎麼做?
如果您認爲您的問題得到解答,請接受相應的答案。 – 2012-04-23 16:02:56