algo9-2.cpp

来自「清华大学《数据结构》教材第二版对应的C++教学程序」· C++ 代码 · 共 37 行

CPP
37
字号
 // algo9-2.cpp 检验bo9-1.cpp(有序表部分)的程序
 #include"c1.h"
 #define N 11 // 数据元素个数
 typedef int KeyType; // 设关键字域为整型
 struct ElemType // 数据元素类型
 {
   KeyType key; // 关键字域
   int others; // 其它部分
 }r[N]={{5,1},{13,2},{19,3},{21,4},{37,5},{56,6},{64,7},{75,8},
	{80,9},{88,10},{92,11}}; // 数据元素(以教科书P.219的数据为例),全局变量
 #include"c9.h"
 #include"c9-1.h"
 #include"bo9-1.cpp"

 void print(ElemType c) // Traverse()调用的函数
 {
   printf("(%d %d) ",c.key,c.others);
 }

 void main()
 {
   SSTable st;
   int i;
   KeyType s;
   Creat_Ord(st,N); // 由全局数组产生非降序静态查找表st
   Traverse(st,print); // 顺序输出非降序静态查找表st
   printf("\n");
   printf("请输入待查找值的关键字: ");
   scanf("%d",&s);
   i=Search_Bin(st,s); // 折半查找有序表
   if(i)
     printf("(%d %d) %d是第%d个记录的关键字\n",st.elem[i].key,st.elem[i].others,s,i);
   else
     printf("没找到\n");
   Destroy(st);
 }

⌨️ 快捷键说明

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