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

📄 hashlistmain1.cpp

📁 实现散列表操作 大学数据结构教材要求实验
💻 CPP
字号:
#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);
}

⌨️ 快捷键说明

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