首页 > 编程语言 > 详细

哈希表排序O(m+n)

时间:2020-02-28 14:18:23      阅读:62      评论:0      收藏:0      [点我收藏+]
#include<iostream> using namespace std; const int maxn = 1000; int main() { int nums[10] = { 12, 88, 66, 122, 43, 66, 88, 99, 666, 888}; int hash_map[maxn]={0}; for(int i = 0; i < 10; i++) { hash_map[nums[i]]++; } for(int i = 0; i < maxn; i++) { for(int j = 0; j < hash_map[i]; j++) { cout<<i<<" "; } } cout<<endl; return 0; }

技术分享图片
哈希表排序优点:时间复杂度为O(表长+n) n为元素个数.
缺点:只能对正整数排序,且哈希表长度必须大于最大待排序数字.

哈希表排序O(m+n)

原文:https://blog.51cto.com/14472348/2474199

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!