Sorting hash table O (m + n)

#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;
}

Sorting hash table O (m + n)
Hash table is sorted advantages: time complexity is O (table length + n) n is the number of elements.
Disadvantages: Only positive integer sort and hash table to be sorted must be longer than the maximum number.

Guess you like

Origin blog.51cto.com/14472348/2474199