随笔分类 - Algorithm
摘要:之前碰到个非常有意思的题目,是关于排序算法的题目:已知:一个数组:array,数组元素:0或1或2求解:将数组按照0-1-2排序? 1 template 2 void Swap(T& t1, T& t2) 3 { 4 T tmp = t1; 5 t1 = t2; 6 ...
阅读全文
摘要:/*** 获取制定范围的随机数.** 数据范围:uiStart~uiEnd (uiStart > uiEnd),随机数包括uiStart, uiEnd的取值.*/ 1 // GetRand from uiStart to uiEnd. 2 typedef unsigned int UINT; 3 UINT GetRand(UINT uiStart, UINT uiEnd) 4 { 5 if(uiStart > uiEnd) 6 { 7 cout<<"uiStart have to less than uiEnd."<<endl; 8 re
阅读全文
摘要:1 // Swap 2 void Swap(int* a, int* b) 3 { 4 int tmp = *a; 5 *a = *b; 6 *b = tmp; 7 } 8 9 // GCD: Greatest Common Divisor10 int GCD(int i, int j)11 {12 if(i < 0 || j < 0)13 return 0;14 15 if(i < j)16 Swap(&i, &j); // Make sure i > j.17 18 if(j == 0) return i;19 20 ...
阅读全文
浙公网安备 33010602011771号