#include<iostream>
 #include<ctime>
 #include <stdio.h>
 #include<cstring>
 #include<cstdlib>
 #include <map>
 #include <string>
 using namespace std;
 // A utility function to get maximum value in arr[]
 int getMax(int arr[], int n)
 {
     ];
     ; i < n; i++)
         if (arr[i] > mx)
             mx = arr[i];
     return mx;
 }

 // A function to do counting sort of arr[] according to
 // the digit represented by exp.
 void countSort(int arr[], int n, int exp)
 {
     int output[n]; // output array
     ] = {};

     // Store count of occurrences in count[]
     ; i < n; i++)
         count[ (arr[i]/exp)% ]++;

     // Change count[i] so that count[i] now contains actual position of
     // this digit in output[]
     ; i < ; i++)
         count[i] += count[i-];

     // Build the output array
     ; i >= ; i--) {
         output[count[(arr[i]/exp)%]-] = arr[i];
         count[(arr[i]/exp)%]--;
     }

     // Copy the output array to arr[], so that arr[] now
     // contains sorted numbers according to curent digit
     ; i < n; i++)
         arr[i] = output[i];
 }

 // The main function to that sorts arr[] of size n using Radix Sort
 void radixsort(int arr[], int n)
 {
     // Find the maximum number to know number of digits
     int m = getMax(arr, n);

     // Do counting sort for every digit. Note that instead of passing digit
     // number, exp is passed. exp is 10^i where i is current digit number
     ; m/exp > ; exp *= )
         countSort(arr, n, exp);
 }

 // A utility function to print an array
 void print(int arr[], int n)
 {
     ; i < n; i++)
         cout << arr[i] << " ";
 }
 #if TEST
 int main(){
     , , , , , , , };
         ]);
         radixsort(arr, n);
         print(arr, n);
 }
 #endif

基数排序(radix sort)的更多相关文章

  1. 经典排序算法 - 基数排序Radix sort

    经典排序算法 - 基数排序Radix sort 原理类似桶排序,这里总是须要10个桶,多次使用 首先以个位数的值进行装桶,即个位数为1则放入1号桶,为9则放入9号桶,临时忽视十位数 比如 待排序数组[ ...

  2. 学习算法-基数排序(radix sort)卡片分类(card sort) C++数组实现

    基数排序称为卡片分类,这是一个比较早的时间越多,排名方法. 现代计算机出现之前,它已被用于排序老式打孔卡. 说下基数排序的思想.前面我有写一个桶式排序,基数排序的思想是桶式排序的推广. 桶式排序:ht ...

  3. 桶排序/基数排序(Radix Sort)

    说基数排序之前,我们先说桶排序: 基本思想:是将阵列分到有限数量的桶子里.每个桶子再个别排序(有可能再使用别的排序算法或是以递回方式继续使用桶排序进行排序).桶排序是鸽巢排序的一种归纳结果.当要被排序 ...

  4. 小小c#算法题 - 9 - 基数排序 (Radix Sort)

    基数排序和前几篇博客中写到的排序方法完全不同.前面几种排序方法主要是通过关键字间的比较和移动记录这两种操作来实现排序的,而实现基数排序不需要进行记录项间的比较.而是把关键字按一定规则分布在不同的区域, ...

  5. [转] 经典排序算法 - 基数排序Radix sort

    原理类似桶排序,这里总是需要10个桶,多次使用 首先以个位数的值进行装桶,即个位数为1则放入1号桶,为9则放入9号桶,暂时忽视十位数 例如 待排序数组[62,14,59,88,16]简单点五个数字 分 ...

  6. 排序算法七:基数排序(Radix sort)

    上一篇提到了计数排序,它在输入序列元素的取值范围较小时,表现不俗.但是,现实生活中不总是满足这个条件,比如最大整形数据可以达到231-1,这样就存在2个问题: 1)因为m的值很大,不再满足m=O(n) ...

  7. [MIT6.006] 7. Counting Sort, Radix Sort, Lower Bounds for Sorting 基数排序,基数排序,排序下界

    在前6节课讲的排序方法(冒泡排序,归并排序,选择排序,插入排序,快速排序,堆排序,二分搜索树排序和AVL排序)都是属于对比模型(Comparison Model).对比模型的特点如下: 所有输入ite ...

  8. 基数排序(Radix Sort)

    基数排序(Radix Sort) 第一趟:个位 收集: 第二趟:十位 第三趟:百位 3元组 基数排序--不是基于"比较"的排序算法 递增就是把收集的过程返过来 算法效率分析 需要r ...

  9. 【算法】基数排序(Radix Sort)(十)

    基数排序(Radix Sort) 基数排序是按照低位先排序,然后收集:再按照高位排序,然后再收集:依次类推,直到最高位.有时候有些属性是有优先级顺序的,先按低优先级排序,再按高优先级排序.最后的次序就 ...

随机推荐

  1. cowboy-高性能简洁的erlang版web框架

    那么Cowboy是什么呢? Cowboy is a small, fast and modular HTTP server written in Erlang. 其定位非常明确: Cowboy aim ...

  2. 在cmd下编译一个简单的servlet时出现程序包javax.servlet不存在

    由于servlet和JSP不是Java平台JavaSE(标准版)的一部分,而是Java EE(企业版)的一部分,因此,必须告知编译器servlet的位置. 解决“软件包 javax.servlet不存 ...

  3. Android 服务类Service 的详细学习

    http://blog.csdn.net/vipzjyno1/article/details/26004831 Android服务类Service学习四大组建   目录(?)[+] 什么是服务 服务有 ...

  4. linux tail命令的使用方法详解(转)

    本文介绍Linux下tail命令的使用方法.linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新 ...

  5. linux 访问tomcat 管理页面时 You are not authorized to view this page 403(真实可用)

    ava代码 收藏代码 You are not authorized to view this page. If you have not changed any configuration files ...

  6. Jquery 获取URL参数

    使用jquery获取url以及使用jquery获取url参数是我们经常要用到的操作 1.jquery获取url很简单,代码如下 1.window.location.href; 其实只是用到了javas ...

  7. centos6.4yum搭建lamp环境

    1.配置防火墙,开启80端口.3306端口vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 8 ...

  8. Hadoop之伪分布环境搭建

    搭建伪分布环境 上传hadoop2.7.0编译后的包并解压到/zzy目录下 mkdir /zzy 解压 tar -zxvf hadoop.2.7.0.tar.gz -C /zzy     配置hado ...

  9. Swift Tour 随笔总结 (1)

    let Constant var Variable let implicitInteger = 70 let implicitDouble = 70.0 let explicitDouble: Dou ...

  10. c++字符串详解(转)

    之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必担心内存是否足够.字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是 ...