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

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

#include 
#include
#include
using namespace std;class CountingSort {public: int* countingSort(int* A, int n) { // write code here int* counting = new int[1000]; int* tmp = new int[n]; for(int i = 0; i < n; i++){ tmp[i] = A[i]; } fill(counting, counting+1000, 0); for(int i = 0; i < n; i++){ counting[A[i]]++; } for(int i = 1; i < 1000; i++){ counting[i] += counting[i-1]; } cout<<"counting:"<
= 0; j--){ A[counting[tmp[j]]-1] = tmp[j]; counting[tmp[j]]--; } delete [] tmp; delete [] counting; return A; }};int main(){ int a[13] = {
54,35,48,36,27,12,44,44,8,14,26,17,28}; int* res; CountingSort sorter; res = sorter.countingSort(a, 13); cout<<"after sorting:"<

 

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

你可能感兴趣的文章
Linux学习总结(4)——Centos6.5使用yum安装mysql——快速上手必备
查看>>
Spring Boot学习总结(1)——Spring Boot入门
查看>>
C/C++ 宏带来的奇技淫巧 转载
查看>>
CocoaPods requires your terminal to be using UTF-8 encoding
查看>>
CSS3 圆角(border-radius)
查看>>
最大子数组
查看>>
用telnet命令,POP3接收邮件
查看>>
Nginx 关于 location 的匹配规则详解
查看>>
OutputStream、InputStream 、FileOutputStream、FileInputStream,字节流API
查看>>
10. Python面向对象
查看>>
python3与 python2 urllib模块区别
查看>>
关于props 和state
查看>>
跟我学算法-tensorflow 实现线性拟合
查看>>
redis使用管道pipeline提升批量操作性能(php演示)
查看>>
python: file_handling 解决工作中出现的文件处理需求
查看>>
HTML5 拖放(Drag 和 Drop)功能开发——浅谈dataTransfer对象
查看>>
灰度图像亮度对比度调整的简单代码
查看>>
shell测试题上机实验
查看>>
[转]二维数组和二级指针的传递问题
查看>>
nginx+fastcgi+c/c++搭建高性能Web框架
查看>>