标签:
//获取末尾数 int getmantissa(int num, int digits) { int temp = 1; for (int x = 0; x < digits - 1; ++x) temp *= 10; return (num / temp) % 10; } void radixsort(struct SQ_LIST *v) { int digit = 1; //获取位数 int save[10][100001]; for (int i = 0, p = 10; i < v->Length; ++i) while (v->elem[i].ID >= p) { p *= 10; ++digit; } //初始化二位数组每行的首元 for (int x = 0; x < 10; x++) { save[x][0] = 0; } //基数排序 for (int i = 1; i <= digit; i++) { for (int x = 0; x < v->Length+1; ++x) { int mantissa = getmantissa(v->elem[x].ID, i); int index = ++save[mantissa][0]; //每行的首元存储每行数据量 save[mantissa][index] = v->elem[x].ID; } //合并 for (int i = 0, x = 0; i < 10; i++) { for (int j = 0; j < save[i][0]; ++j) v->elem[x++].ID = save[i][j + 1]; save[i][0] = 0; //重新初始化每行首单元 } } }
标签:
原文地址:http://www.cnblogs.com/INnoVationv2/p/5505609.html