Chinaunix
标题:
哈希
[打印本页]
作者:
framily
时间:
2015-05-10 08:40
标题:
哈希
#include <iostream>
using namespace std;
enum {COUNT=17};
typedef int DATA;
struct SNode
{
DATA data;
SNode* pNext;
};
SNode* g_hash[COUNT]={NULL};
void SetAt(DATA data)
{
int n = data%COUNT;
SNode* p = new SNode;
p->data = data;
p ->pNext = g_hash[n];
g_hash[n] = p;
}
bool Lookup(DATA data)
{
int n = data%COUNT;
SNode* p = g_hash[n];
while(p)
{
if (p->data == data)
return true;
p->pNext;
}
return false;
}
int main()
{
SetAt(32);
SetAt(32+17);
SetAt(536);
SetAt(2267);
SetAt(2257);
SetAt(24);
SetAt(996);
SetAt(43758);
SetAt(343463);
SetAt(23234);
SetAt(6666);
if (Lookup(48))
cout << "找到了" << endl;
else
cout << "没有找到" << endl;
return 0;
}
复制代码
作者:
dorodaloo
时间:
2015-05-12 11:00
这个方法很好很牛逼
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2