查找、排序综合实验(8)
时间:2025-04-21
时间:2025-04-21
对记录序列(查找表):{55,13,23,72,109,67,2,78,13}分别实现如下操作:1)顺序查找;2)分别使用直接插入排序、冒泡排序、快速排序对原纪录序列进行排序(暂时人工排序);3)对排好序的纪录序列表进行折半查找;4)利用原纪录序列建立一颗二叉排序树,并在其上实现特定关键字值结点的查找;5)按照“除留余数法”哈希构造函数和线性探测再散列的冲突处理方法创建表长为m=11的哈希表
《
数据结构
》实验报告
-7-
void insertbst(bstree *bst,int k) { bstree s; if(*bst==NULL)
{ s=(bstnode*)malloc(sizeof(bstnode)); s->key=k; s->lchild=NULL; s->rchild=NULL; *bst=s; } else if(k<(*bst)->key) insertbst(&((*bst)->lchild),k); else if(k>(*bst)->key) insertbst(&((*bst)->rchild),k); } void creatbstree(bstree *bst) { int k; *bst=NULL; cout<<"输入元素:"<<endl; cin>>k; while(k!=0) { insertbst(bst,k); cout<<"输入元素:"<<endl; cin>>k; } } //二叉树查找 int searchbst(bstree bst,int k) { if(!bst)return NULL; else if(bst->key==k) { cout<<"输出特定元素:"<<bst->key<<endl; return 1; } else if(k<bst->key) searchbst(bst->lchild,k); else searchbst(bst->rchild,k); return 0; }