⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hash.cpp

📁 数据结构算法之一
💻 CPP
字号:
// Hash.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Hash.h"

int main(int argc, char* argv[])
{	HashTable H;
	KeyType K="";
	int p,j,c=0;
	char t;
	H.elem=(ElemType *)malloc(TABLE_LEN * sizeof(ElemType));
	cout<<"\t\t\tHASHTABLE ARITHMATIC"<<endl;
	cout<<"(Please Input the total number of HashTable,for example:30):  ";
 cin>>H.count;
for(int i=0;i<TABLE_LEN;i++)
{ strcpy(H.elem[i].key,NULLKEY);
}//初始化为空串
 
for(i=0;i<H.count;i++)
 {
  cout<<"Input name["<<i<<"] : ";
  cin>>K;
 p=Hash(K);
if(strcmp(H.elem[p].key,NULLKEY)!=0)
 collision(H,p,++c);// 双哈希再散列 

 strcpy(H.elem[p].key,K);
 }//初始化赋值


cout<<"=====================Hash Table==========================="<<endl;

for( i=j=0;i<TABLE_LEN;i++)
{if(strcmp(H.elem[i].key,"")!=0){
 if(j%2==0&&j!=0) cout<<endl;
 cout<<"pos: "<<i<<"  key: \""<<H.elem[i].key<<"\"\t";
 j++;
   } 
}
cout<<"collision :"<<c<<endl;
cout<<"=========================================================="<<endl;
//显示哈希表

do{
cout<<"Input the name you want to search: ";
 cin>>K;
 c=0;
 if(SearchHash(H,K,p,c)==SUCCESS){
	 cout<<"pos :"<<p<<"  key :"<<H.elem[p].key<<"   collision :"<<c<<endl;}
 else {
	 cout<<"not find!!!"<<endl;}	
	cout<<"Next to search?Yes(y) or NO?  :";
	cin>>t;
}while(t=='y'||t=='Y');//查找功能
return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -