第十三周 【项目2
来源:互联网 发布:mysql获取当前日期 编辑:程序博客网 时间:2024/05/21 18:45
- /* 程序头部注释开始
- * 程序的版权和版本声明部分
- * Copyright (c) 2017, 烟台大学计算机学院学生
- * All rights reserved.
- * 文件名称: danlianbao.cpp
- * 作 者: 胡俊超
- * 完成日期: 2017 年 11 月 30 日
- * 版 本 号: v1.0
- * 对任务及求解方法的描述部分
- * 问题描述:
- 认真阅读并验证分块查找算法。请用22,4,23,11,20,2,15,13,30,45,26,34,29,35,26,36,55,98,56, 74,61,90,80,96,127,158,116,114,128,113,115,102,184,211,243,188,187,218,195,210,279,307,492,452,408,361,421,399,856,523,704,703,697,535,534,739(共n=56个数据,每块数据个数s=8)作为数据表,自行构造索引表,分别对查找61、739、200进行测试。
#include <stdio.h>#define MAXL 100 //数据表的最大长度#define MAXI 20 //索引表的最大长度typedef int KeyType;typedef char InfoType[10];typedef struct{ KeyType key; //KeyType为关键字的数据类型 InfoType data; //其他数据} NodeType;typedef NodeType SeqList[MAXL]; //顺序表类型typedef struct{ KeyType key; //KeyType为关键字的类型 int link; //指向对应块的起始下标} IdxType;typedef IdxType IDX[MAXI]; //索引表类型int IdxSearch(IDX I,int m,SeqList R,int n,KeyType k){ int low=0,high=m-1,mid,i; int b=n/m; //b为每块的记录个数 while (low<=high) //在索引表中进行二分查找,找到的位置存放在low中 { mid=(low+high)/2; if (I[mid].key>=k) high=mid-1; else low=mid+1; } //应在索引表的high+1块中,再在线性表中进行顺序查找 i=I[high+1].link; while (i<=I[high+1].link+b-1 && R[i].key!=k) i++; if (i<=I[high+1].link+b-1) return i+1; else return 0;}int main(){ int i,n=25,m=5,j; SeqList R; IDX I= {{14,0},{34,5},{66,10},{85,15},{100,20}}; KeyType a[]= {8,14,6,9,10,22,34,18,19,31,40,38,54,66,46,71,78,68,80,85,100,94,88,96,87}; KeyType x=85; for (i=0; i<n; i++) R[i].key=a[i]; j=IdxSearch(I,m,R,n,x); if (j!=0) printf("%d是第%d个数据\n",x,j); else printf("未找到%d\n",x); return 0;}
阅读全文
0 0
- 第十三周项目2
- 第十三周项目2
- 第十三周项目2
- 第十三周项目2
- 第十三周 【项目2
- 第十三周【项目2
- 第十三周 【项目2
- 第十三周 【项目2
- 第十三周 【项目2
- 第十三周项目2
- 第十三周项目2
- 第十三周项目2
- 第十三周 【项目2
- 第十三周项目2(2)
- 第十三周项目1---2
- 第十三周项目2 成绩单
- 第十三周项目4--2
- 第十三周项目1-2
- 数据结构第四周项目-建设双链表算法库
- MD5加密 工具类,拿来可用
- SQL语句中的rank () over , row_number() over ,rank_dense ()
- 使用PhotoView时出现Multiple dex files define Luk/co/senab/photoview/BuildConfig错误
- 在项目中使用分库分表中间件Zdal
- 第十三周 【项目2
- Latex \bibliographystyle
- Python 学习日记-01.中文编码声明# coding:UTF-8
- java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
- 不会代码的我,让超模走进了我的游戏...
- 2017年11月学习心得报告
- Python数据库编程
- 【Android学习】动画
- JAXB基本使用