电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

数据结构实验2查找算法的实现和应用VIP免费

数据结构实验2查找算法的实现和应用_第1页
1/10
数据结构实验2查找算法的实现和应用_第2页
2/10
数据结构实验2查找算法的实现和应用_第3页
3/10
实验2 查找算法的实现和应用  实验目的 1. 熟练掌握静态查找表的查找方法; 2. 熟练掌握动态查找表的查找方法; 3. 掌握hash表的技术.  实验内容 1. 用二分查找法对查找表进行查找; 2. 建立二叉排序树并对该树进行查找; 3. 确定hash函数及冲突处理方法,建立一个hash表并实现查找。 1.二分查找 #include using namespace std; #define INVALID_INDEX -100 int IntCompare(const int& a, const int& b, void* param) { return a - b; } template int BinarySearch(const T1* theArray, int length, const T2& key, int (*compare)(const T1&, const T2&, void* param), void *param) { int indexRet = INVALID_INDEX; int mid = length / 2; int cmp = compare(theArray[mid], key, param); if (cmp == 0) { indexRet = mid; } else if (length != 1) { if (cmp < 0 && length != 1) { indexRet = BinarySearch(theArray + mid, length - mid, key, compare,param); if (indexRet != INVALID_INDEX) { indexRet += mid; } } else { indexRet = BinarySearch(theArray, mid, key, compare, param); } } return indexRet; } int main() { int length = 0; int i = 0; int key = 0; int index = INVALID_INDEX; cout <<"请输入元素的个数:"<> length; int* aArray = new int[length]; cout<<"请输入要输入的元素:"<> aArray[i]; } cout<<"要查找的元素:"<> key&&key != 'F'){ index = BinarySearch(aArray, length, key, IntCompare, NULL); if (index == INVALID_INDEX) { cout << "The element is not exist." << endl; } else { cout << "The element position is " << index << "." << endl; } delete aArray; } return 0; } 2 二叉排序树 #include #include #include using namespace std; typedef int keyType; typedef struct Node { keyType key; struct Node* left; struct Node* right; struct Node* parent;...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

数据结构实验2查找算法的实现和应用

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部