#include<iostream.h>
#include"hashList1.h"
#include "LinkHashList1.h"
void UseArrayHashList();
void UseLinkHashList();
void main()
{
UseArrayHashList();
cout<<endl;
UseLinkHashList();
cout<<endl;
}
void UseArrayHashList()
{
ArrayHashList ht;
int m;
InitHashList(ht,m);
ElemType x;
ElemType a[7]={45,28,34,50,66,73,82};
int i,j;
cout<<"向散列表插入了数组a[7]={45,28,34,50,66,73,82}中";
cout<<"的所有元素!"<<endl;
for(i=0;i<7;i++)Insert(ht,m,a[i]);
cout<<"从键盘上输入一批整数插入到散列表中,用-1作为结束!"<<endl;
do {
cin>>x;
if(x==-1)break;
Insert(ht,m,x);
} while(1);
PrintHashList(ht,m);
cout<<"从键盘上输入一批待从散列表中查找的整数,用-1作为结束!"<<endl;
do {
cin>>x;
if(x==-1)break;
Insert(ht,m,x);
} while(1);
PrintHashList(ht,m);
cout<<"从键盘上输入一批待从散列表中查找的整数,用-1作为结束!"<<endl;
do {
cin>>x;
if(x==-1)break;
if((j=Search(ht,m,x))!=-1)
cout<<"从散列表中查找"<<x<<"成功!返回下标值为"<<j<<endl;
else
cout<<"从散列表中查找"<<x<<"失败!"<<endl;
} while(1);
cout<<"从键盘上输入两个整数插入到散列表中!"<<endl;
for(i=0;i<2;i++){
cin>>x;
Insert(ht,m,x);
}
PrintHashList(ht,m);
DeleteHashList(ht);
}
void UseLinkHashList()
{
LinkHashList ht;
int m;
InitHashList(ht,m);
ElemType x;
ElemType a[7]={45,28,34,50,66,73,82};
int i;
cout<<"向散列表插入了数组a[7]={45,28,34,50,66,73,82}中";
cout<<"的所有元素!"<<endl;
for(i=0;i<7;i++)Insert(ht,m,a[i]);
cout<<"从键盘上输入一批整数插入到散列表中,用-1作为结束!"<<endl;
do {
cin>>x;
if(x==-1)break;
Insert(ht,m,x);
} while(1);
PrintHashList(ht,m);
cout<<"从键盘上输入一批待从散列表中查找的整数,用-1作为结束!"<<endl;
do {
cin>>x;
if(x==-1)break;
ElemType* y;
if((y=Search(ht,m,x))!=NULL)
cout<<"散列表中查找"<<x<<"成功!返回地址值为"<<y<<endl;
else
cout<<"从散列表中查找"<<x<<"失败!"<<endl;
} while(1);
cout<<"从键盘上输入两个整数插入到散列表中!"<<endl;
for(i=0;i<2;i++){
cin>>x;
Insert(ht,m,x);
}
PrintHashList(ht,m);
DeleteHashList(ht,m);
}