-
大小: 42KB文件類型: .rar金幣: 1下載: 0 次發(fā)布日期: 2021-01-07
- 語言: 其他
- 標(biāo)簽:
資源簡介
哈希查找:
1、 哈希表類的哈希函數(shù)采用除留余數(shù)法哈希函數(shù);
2、 解決哈希沖突的函數(shù)采用開放定址法中的線性探察法。
3、 建立一個由10個數(shù)據(jù)元素組成的集合;
4、 測試哈希表長度m=13和m=11兩種情況下的哈希表,并查找其中的幾個元素。
代碼片段和文件信息
#include?
typedef?int?KeyType;
#include?“DataType.h“
#include?“HashTable.h“
#include?“stdlib.h“
void?main(void)
{
int?i?jn=10;
cout<<“請輸入哈希表長度(11或者13)“< int?x;cin>>x;
HashTable?myHashTable(x);
DataType?a[]={100150200250300350400450500550};
DataType?item;?
for(i?=?0;?i? myHashTable.Insert(a[i]);
for(i?=?0;?i? {
j?=?myHashTable.Find(a[i]);
if(j?>?0)
{
item?=?myHashTable.GetValue(j);
cout?<“j?=?“?< }
}
char?m=‘y‘;
for(;m!=‘n‘?&&?m!=‘N‘;)
{
cout<<“請輸入要查找的數(shù)“< int?y;cin>>y;
int?k?=?myHashTable.IsIn(y);
if(k?==?1)?cout?<“數(shù)據(jù)元素“< else?cout?<“數(shù)據(jù)元素“< cout<<“是否繼續(xù)查找,輸入Y或者N“< cin>>m;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????218??2003-09-06?17:32??哈希表類\Datatype.h
?????文件????????872??2010-06-22?17:53??哈希表類\HashTable.cpp
?????文件?????225363??2010-06-22?11:32??哈希表類\HashTable.exe
?????文件???????2286??2010-06-22?10:46??哈希表類\HashTable.h
?????目錄??????????0??2010-06-22?17:56??哈希表類
-----------?---------??----------?-----??----
???????????????228739????????????????????5
評論
共有 條評論