Given tree integers a, b,c. Write a function: int median (int a,int b,int c) to get the median number among a,b,c. Can not use sort, the times of integer operations (e.g. compare, + - * /, bit computing) the less the better. Analyze the best and the worst situation.
---------------------------------------------------------------
int median(int a, int b, int c){
int m = min(a,b);
int n = min(b,c);
int o = min(c,a);
return(m^n^o);
}

本文介绍了一个高效的算法用于计算三个整数中的中位数,不使用排序操作,通过一系列整数运算实现。分析了最优与最坏情况下的时间复杂度。
1375

被折叠的 条评论
为什么被折叠?



