CareerCup Median of three numbers

来源:互联网 发布:树莓派3 网络配置 编辑:程序博客网 时间:2024/04/30 11:41

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);}


0 0
原创粉丝点击