Chapter 02 Looping and counting
来源:互联网 发布:qq偷菜软件 编辑:程序博客网 时间:2024/05/17 03:07
1. 循环不变式(loop invariant)
含义即为有一个变量在循环执行前、中、后的意义是恒定的,在循环体中可能会使变量不符合不变式,应在随后的语句进行矫正。
// 不变式: 目前已写了r行int r = 0;// 将r初始化为0使不变式为真while (r != rows) { // 这里可以认为不变式为真 // 写一行后不变式为假 std::cout << std::endl; // 矫正r的值使不变式再次为真 ++r;}// 这里可以得出不变式为真的结论
2. 对称区间和非对称区间(symmetric ranges and asymmetric ranges)
a. 对非对称区间的使用更为简便,在一个形式为[m,n)的区间包含有n-m个元素,而在形式为[m,n]的区间中则有n-m+1个元素。从区间[0,rows)很容易得到元素的个数,而区间[1,rows]的元素个数没有这么明显;
b. 就空区间而言,在不对称区间和对称区间的差别是特别明显的:如果使用不对称区间,我们可以用[n,n)来表示一个空区间,而对于对称区间却要使用[n,n-1],如果一个区间的末尾比开头小,那么,在设计程序的时候我们就有可能会因此而碰到无穷无尽的麻烦。
- Chapter 02 Looping and counting
- OpenAL Lesson 2: Looping and Fadeaway(转载)
- Looping Techniques
- Chapter 6:Inheritance and Composition
- Chapter 3 Functions and Pointers
- CHAPTER 5 References and Scoping
- chapter 2 CRuntimeClass and CObject
- Chapter 4 Arrays and Pointers
- !!!Chapter 4 Arrays and Pointers
- Chapter 3 - Variables and Expressions
- Chapter 3 | Stacks and Queues
- Chapter 13 Metatables and Metamethods
- Chapter 2 Classes and Objects
- Chapter 4. Arrays and Pointers
- Chapter 1 Arrays and Strings
- Chapter 2: Variables and Constants
- Chapter 3 ADC and DAC
- C++ PP Chapter Ⅴ 循环 and Chapter Ⅵ 分支
- Linux进程控制
- 进程
- 2个通用js树型导航
- magento 自定义布局方式
- Google推荐的15条军规:HTML5代码规范
- Chapter 02 Looping and counting
- 开源的物理引擎
- C++功在不舍(2012.07.09)
- 2012-7-9 周一 计划
- 产品经理如何了解用户需求?
- POJ 1163 The Triangle 简单DP
- Android心得9--Bundle类和Intent意图
- 奇怪!post提交 地址栏参数竟然可见
- Android心得8--Internet