Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

qsort对正负数同时排序的问题

Posted by xiehe at 2006-04-18 19:02:12 on Problem 2526
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator