哈希表 STL map

计数排序时我们使用一个数组来记录出现的数字的次数,而当数据范围太大时,无法建立一个那么大地数组(而且可能空间利用率很低,太浪费),此时可以改用hash table 、 binary search tree等数据结构作为lookup table

#include<cstdio>
#include<map>
#include <iostream>
using namespace std;
int main(){
    map<int,int> b;
    map<int,int>::iterator i;
    int a[10]={
        1,2,10000000,9999,456,1213,232543,43546566,43,56
    };
    for(int i=0;i<10;i++){
        b[a[i]]++;
    }
    for(i=b.begin();i!=b.end();i++){
        cout<<i->first<<' '<<i->second<<"\n";
    }
}

 

posted @ 2015-10-23 12:04  Mose  阅读(211)  评论(0编辑  收藏  举报