在教程 《C++数据结构与算法实现》 的每一篇文章的最后,我们都会给出预期输出结果。
如下所示:
line:180 Pass
line:185 Pass
line:188 Pass
line:188 Pass
line:188 Pass
line:188 Pass
line:188 Pass
line:188 Pass
line:188 Pass
line:188 Pass
line:188 Pass
line:188 Pass
line:190 Pass
line:197 Pass
line:206 Pass
The contents of fifth are: 16 2 77 29
The contents of fifth are: 16 2 77 29 30
The contents of first are: 16 2 77 29 30
line:258 Pass
line:259 Pass
Memory leak report:
No memory leak.
其中, line:180 Pass 表示在这篇文章里的练习作业中的源代码 180行有一个 check 调用。
check 调用
用来判断你的代码实现是否符合期待,如果符合就会输出 Pass。表示你的代码通过了题目设计的测试用例。
如果不符合就会立即退出,并输出 oh no , not pass.
assert 调用检测
有些检测必须要在循环内进行,这时候我们使用的是assert 检测。因为如果用check检查,你写对了,就意味着标准输出也要有很多行输出 Pass,这显然对学习者不方便。
assert检测不通过,会立即终止程序,也会提醒你代码行号。
内存泄露检测
每一个作业都自带内存泄露检测,如上图所示“No memory leak.”,表示没有内存泄露。
否则会输出某个类的对象泄露了几个没有释放。
本文介绍了C++教程中关于数据结构与算法实现的内容,强调了检查函数(check)、assert用法以及内置的内存泄露检测机制,确保代码正确性和资源管理。
1384

被折叠的 条评论
为什么被折叠?



