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 ...
随机推荐
- 使用Blazor WASM实现可取消的多文件带校验并发分片上传
前言 上传大文件时,原始HTTP文件上传功能可能会影响使用体验,此时使用分片上传功能可以有效避免原始上传的弊端.由于分片上传不是HTTP标准的一部分,所以只能自行开发相互配合的服务端和客户端.文件分片 ...
- Go 复合类型之字典类型介绍
Go 复合类型之字典类型介绍 目录 Go 复合类型之字典类型介绍 一.map类型介绍 1.1 什么是 map 类型? 1.2 map 类型特性 二.map 变量的声明和初始化 2.1 方法一:使用 m ...
- Java基础知识1-10
测试要点 一.Java基础 1.常用设计模式有哪些?在项目中有哪里用的到?单例中懒汉饿汉优缺点? 软件设计模式分为三类分别为创建型.结构型.行为型. 1.1创建型 1.1.1单例模式(singleto ...
- 【PHP反序列化】速览
PHP反序列化 一.原理 序列化就是将对象转化成字符串,反序列化相反.数据的格式转换和对象的序列化有利于对象的保存 . 反序列化漏洞:就是php对数据进行反序列化时,没有进行过滤,导致用户可以控制反序 ...
- 告别空指针让代码变优雅,Optional使用图文例子源码解读
一.前言 我们在开发中最常见的异常就是NullPointerException,防不胜防啊,相信大家肯定被坑过! 这种基本出现在获取数据库信息中.三方接口,获取的对象为空,再去get出现! 解决方案当 ...
- 浅析 C# Console 控制台为什么也会卡死
一:背景 1. 讲故事 在分析旅程中,总会有几例控制台的意外卡死导致的生产事故,有经验的朋友都知道,控制台卡死一般是动了 快速编辑窗口 的缘故,截图如下: 虽然知道缘由,但一直没有时间探究底层原理,市 ...
- 自研、好用、够快、稳定、代码可读性强的ORM
Fast Framework 作者 Mr-zhong 代码改变世界.... 一.前言 Fast Framework 基于NET6.0 封装的轻量级 ORM 框架 支持多种数据库 SqlServer O ...
- Isito 入门(八):金丝雀发布
本教程已加入 Istio 系列:https://istio.whuanle.cn 目录 6,金丝雀发布 金丝雀发布 按照流量比例划分 按照 Header 划分 6,金丝雀发布 项目总是处于不断变化之中 ...
- ORACLE SQL语句逻辑读高优化案例
川川找我优化SQL,逻辑读达到398,000,安排一下. SQL和执行计划: SELECT t1.*, t3.bed_number, t3.patient_name, t4.name FROM odw ...
- Python 既是解释型语言,也是编译型语言
哈喽大家好,我是咸鱼 不知道有没有小伙伴跟我一样,刚开始学习 Python 的时候都听说过 Python 是一种解释型语言,因为它在运行的时候会逐行解释并执行,而 C++ 这种是编译型语言 不过我今天 ...