Programming abstractions in C阅读笔记:p181-p183
《Programming Abstractions In C》学习第61天,p181-p183总结。
一、技术总结
1.linear search algorithm
2.lexicographic order(字典顺序)
3.binary search algorithm(二分查找算法)
/*
* 1.二分查找也应用了递归的思想。
* 2.这里的代码只是demo
*/
#include <stdio.h>
#include "strlib.h"
int FindStringInSortedArray(string key, string array[], int n);
static int BinarySearch(string key, string array[], int low, int high);
/*
* Function: FindStringInSortedArray
* Usage: index = FindStringInSortedArray(key, array, n);
* ------------------------------------------------------
* This function searches the array looking for the specified
* key. The argument n specifies the effective size of the
* array, which must be sorted according to the lexicographic
* order imposed by StringCompare. If the key is found, the
* function returns the index in the array at which that key
* appears. (If the key appears more that once in the array,
* any of the matching indices may be return). If the key
* does not exist in the array, the function returns -1. In
* this implementation, FindStringInSortedArray is simply a
* wrapper; all the work is done by the recursive function
* BinarySearch.
*/
int FindStringInSortedArray(string key, string array[], int n) {
return BinarySearch(key, array, 0, n - 1);
}
/*
* Function: BinarySearch
* Usage: index = BinarySearch(key, array, low, high);
* ---------------------------------------------------
* This function does the work for FindStringInSortedArray.
* The only difference is that BinarySearch takes both the
* upper and lower limit of the search.
*/
static int BinarySearch(string key, string array[], int low, int high) {
int mid, cmp;
if (low > high) {
return -1;
}
mid = (low + high) / 2;
cmp = StringCompare(key, array[mid]);
if (cmp == 0) {
return mid;
}
if (cmp < 0) {
return BinarySearch(key, array, low, mid - 1);
} else {
return BinarySearch(key, array, mid + 1, high);
}
}
int main() {
int index;
char *arr[] = {"Programming Abstractions in C", "Hello World", "C"};
index = FindStringInSortedArray("C", arr, 3);
printf("index is: %d", index);
return 0;
}
二、英语总结
1.lecicographic是什么意思?
答:
(1)lexicographic < lexicography: adj. of or relating lexicography(字典的)。
(2)lexicography: lexico-("wordbook",字典) + -graphy("to write")
2.adhere是什么意思?
答:p182,Although most of the recursive functions you encounter are likely to adhere to this style, the definition of the recursion is actually somewhat broader。ad-("to") + haerere("to stick")。vi. to stick firmely(附着,遵循)。后面常接介词to。
三、参考资料
1. 编程
(1)Eric S.Roberts,《Programming Abstractions in C》:https://book.douban.com/subject/2003414
2. 英语
(1)Etymology Dictionary:https://www.etymonline.com
(2) Cambridage Dictionary:https://dictionary.cambridge.org

欢迎搜索及关注:编程人(a_codists)
Programming abstractions in C阅读笔记:p181-p183的更多相关文章
- 《Java编程思想》阅读笔记二
Java编程思想 这是一个通过对<Java编程思想>(Think in java)进行阅读同时对java内容查漏补缺的系列.一些基础的知识不会被罗列出来,这里只会列出一些程序员经常会忽略或 ...
- Mongodb Manual阅读笔记:CH3 数据模型(Data Models)
3数据模型(Data Models) Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mon ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画 学习目标 熟悉蒙皮动画的术语: 学习网格层级变换 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试 代码工程地址: https://github.co ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制 代码工程地址: https://gi ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第四章:Direct 3D初始化
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第四章:Direct 3D初始化 学习目标 对Direct 3D编程在 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数 学习目标: 理解矩阵和与它相关的运算: 理解矩阵的乘 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数 学习目标: 学习如何使用几何学和数字描述 Vecto ...
- 阅读笔记 1 火球 UML大战需求分析
伴随着七天国庆的结束,紧张的学习生活也开始了,首先声明,阅读笔记随着我不断地阅读进度会慢慢更新,而不是一次性的写完,所以会重复的编辑.对于我选的这本 <火球 UML大战需求分析>,首先 ...
- [阅读笔记]Software optimization resources
http://www.agner.org/optimize/#manuals 阅读笔记Optimizing software in C++ 7. The efficiency of differe ...
随机推荐
- VScode+X11支持连接服务器时支持open3d、openCV、matplotlib等可视化
背景 连接服务器以后,想用open3d可视化点云.matplotlib画点图,但是一直不能用,原因也很简单,就是没有配置GUI传输显示,那肯定是要配置X11相关的东西. 过程 服务器 确保服务器下载了 ...
- junit4单元测试报错Invalid project specified
junit4单元测试报错Invalid project specified. 前天在进行单元测试的时候出现了Invalid project specified的报错查了一下发现是项目名字的问题.项目名 ...
- mysql之简单的多表查询
最简单的多表查询需要用到连操作符(join) 1.笛卡儿积 形式为table1 join table2.如: select e.fname,e.lname,d.name from employee e ...
- Redis 6 学习笔记 1 —— NoSQL数据库介绍,Redis常用数据类型
NoSQL数据库介绍(了解) 技术的分类1.解决功能性的问题:Java.Jsp.RDBMS.Tomcat.HTML.Linux.JDBC.SVN,2.进一步地,解决系统功能扩展性的问题:Struts. ...
- 文心一言 VS 讯飞星火 VS chatgpt (121)-- 算法导论10.4 2题
二.用go语言,给定一个n结点的二叉树,写出一个 O(n)时间的递归过程,将该树每个结点的关键字输出. 文心一言: 在Go语言中,你可以使用递归函数来遍历二叉树的所有节点,并输出每个节点的关键字.以下 ...
- CAP 定理的含义(转)
分布式系统(distributed system)正变得越来越重要,大型网站几乎都是分布式的. 分布式系统的最大难点,就是各个节点的状态如何同步.CAP 定理是这方面的基本定理,也是理解分布式系统的起 ...
- pkg-config手册
定义 pkg-config是一款用于返回已安装库元信息的工具: (语法)概要 pkg-config [--modversion] [--help] [--print-errors] [--silenc ...
- k8s-服务网格实战-配置 Mesh(灰度发布)
在上一篇 k8s-服务网格实战-入门Istio中分享了如何安装部署 Istio,同时可以利用 Istio 实现 gRPC 的负载均衡. 今天我们更进一步,深入了解使用 Istio 的功能. 从 Ist ...
- dbeaver软件的使用
dbeaver软件的使用 一.dbeaver简介: dbeaver是免费和开源(GPL)为开发人员和数据库管理员通用数据库工具. DBeaver [1] 是一个通用的数据库管理工具和 SQL 客户端, ...
- 洛谷4159 [SCOI2009] 迷路(矩阵快速幂,拆点)
题意:该有向图有 n 个节点,节点从 1至 n 编号,windy 从节点 1 出发,他必须恰好在 t 时刻到达节点 n.现在给出该有向图,你能告诉 windy 总共有多少种不同的路径吗?答案对2009 ...