Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
qsort对正负数同时排序的问题qsort对正负数同时排序的问题 int cmp(const void* a,const void* b) { if (*(double**)a!=*(double**)b) return *(double**)a>*(double**)b?1:-1; else return *((double**)a+1)>*((double**)b+1)?1:-1; } double a[MAXN][2]; qsort(a,n,sizeof(a[0]),cmp); 因为负数的二进制表示形式问题<第一位为1> 导致cmp函数判断了负数比正数大 导致排序之后负数排在了正数后面 怎样解决这个问题让qsort可以处理符号排序 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator