Algorithm Intro - Radix Sort
来源:互联网 发布:淘宝客教学视频 编辑:程序博客网 时间:2024/06/05 10:51
int get0to9(int n, int d)
{
while(n != 0 && d > 0) {
n /= 10; d--;
}
return n % 10;
}
void count_sort0to9(vector<int> &v, int index)
{
int count[10];
vector<int> b = v;
for(int i = 0; i < 10; i++) count[i] = 0;
for(int i = 0; i < v.size(); i++) {
int d = get0to9(v[i], index);
count[d]++;
}
for(int i = 1; i < 10; i++) count[i] += count[i - 1];
for(int i = v.size() - 1; i >= 0; i--) {
int d = get0to9(v[i], index);
b[count[d] - 1] = v[i];
count[d]--;
}
for(int i = 0; i < b.size(); i++) {
cout << b[i] << " ";
}
cout << endl;
v = b;
}
// d denote max components 10-base of number
// e.g. 77 => 2, 1001 => 4
void radix_sort(vector<int>&v, int d)
{
for(int i = 0 ; i < d; i++) {
count_sort0to9(v, i);
}
}
- Algorithm Intro - Radix Sort
- Algorithm Intro - Insert Sort
- Algorithm intro - Select Sort
- Algorithm Intro - Bubble Sort
- Algorithm Intro - Merge Sort
- Algorithm Intro - Quick Sort
- Algorithm Intro - Count Sort
- Radix sort
- Radix Sort
- radix sort
- Radix Sort
- radix-sort
- radix sort
- radix sort
- Radix Sort
- radix sort &&bucket sort
- Radix Sort 基数排序
- radix sort 基数排序
- HDU 1254:推箱子【DFS && BFS】
- 人见人爱A+B(2)
- Fragment详解之二——基本使用方法
- C#调用C++ DLL 中定义的函数
- 使用updatePanel从服务器调用方法
- Algorithm Intro - Radix Sort
- 创新实验室实习生每周工作总结【实习第十八周】
- 贝叶斯网的R实现( Bayesian networks in R)bnlearn(1)
- Python中安装以及配置easy_install
- [leetcode oj 217]Contains Duplicate
- 最有效地使用PNG之续篇:Zopfli优化
- Fragment详解之三——管理Fragment(1)
- 数据结构-赫夫曼树
- 稳定婚姻问题