博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
算法笔记 --- Radix Sort
阅读量:7060 次
发布时间:2019-06-28

本文共 856 字,大约阅读时间需要 2 分钟。

#include 
#include
#include
#include
#include
using namespace std;class RadixSort {public: int* radixSort(int* A, int n) { // write code here //because value is smaller than 2000, so => 1000 queue
bucket[10]; int d, index, k, p = 3; for(int i = 0; i <= p; i++){ d = pow(10, i); for(int j = 0; j < n; j++){ index = (A[j] / d) % 10; bucket[index].push(A[j]); } k = 0; for(int i = 0; i < 10; i++){ while(!bucket[i].empty()){ A[k++] = bucket[i].front(); bucket[i].pop(); } } } return A; }};int main(){ int a[13] = { 54,35,48,36,27,12,44,44,8,14,26,17,28}; int* res; RadixSort sorter; res = sorter.radixSort(a, 13); cout<<"after sorting:"<

 

转载于:https://www.cnblogs.com/zhongzhiqiang/p/5791091.html

你可能感兴趣的文章
测试WPF绑定bug
查看>>
Cocoa.DesignPattern.Factory
查看>>
Openflow1.3
查看>>
jetty服务器
查看>>
thinkcmf的基于tp5行为扩展的静态缓存
查看>>
MySQL存储过程实现分页及变量的定义
查看>>
shell脚本攻略读书笔记
查看>>
****** 二十八 ******、软设笔记【数据库】-分布式数据库、特点、数据存储、DBMS组成...
查看>>
约束、自定义异常、加密、日志处理
查看>>
gitlab出现502报错解决
查看>>
HK游记 Day2迪斯尼(下)
查看>>
Centos7安装jdk8
查看>>
<Android 基础(一)> Service
查看>>
python编程基础之二十六
查看>>
Java数据结构
查看>>
排序算法之快速排序
查看>>
MapReduce实例-NASA博客数据频度简单分析
查看>>
sqoop 常用命令整理(二)
查看>>
Jenkins安装
查看>>
06-图3 六度空间
查看>>