当前位置:网站首页>Optimization is a kind of habit low starting point is the "standing near the critical"
Optimization is a kind of habit low starting point is the "standing near the critical"
2022-08-11 04:52:00 【a music】
1. Example: dynamic insertion and deletion of arrays
Consider the critical value
This critical value, not necessarily the last element

- Delete an element:

The first method: when the maximum value is obtained: i=size-1, the expression is: elements[size-2]=elements[size-1]
Second approach: When the maximum value is obtained: i=size-1, the expression is: elements[size-1]=elements[size] This is obviously not in line with the design. For example, the current array has size elements, thenThe last element should be elements[size-1]
In fact, crossing the boundary is also a thinking angle. If you stand at the covered angle, then the last covered element in the critical is the penultimate element of the current array elements[size-2]
The second approach: The loop judgment condition should be modified to be correct: for(int i = index; i < size-1; i++)
The first approach: is to stand at the cover angle, and also stand close to the 'threshold' (closer to the last element)The angle of font>, not easy to make mistakes, recommended
- Add an element:

In adding elements here: There is no problem with practice 1 and practice 2, but it is recommended,
Uniform Habits: The starting point is to "stand near critical"
边栏推荐
猜你喜欢
随机推荐
优先级队列
延长经济保险(jeecgboot)
快速使用UE4制作”大场景游戏“
The principle, architecture, implementation, practice of "transfer" and "search", no need to be afraid of interviews
如何给网页添加icon图标?
Redis: Solve the problem of modifying the same key with distributed high concurrency
jwsManager服务接口实现类-jni实现
使用百度EasyDL实现施工人员安全装备检测
【实战场景】商城-折扣活动设计方案
解决多线程调用sql存储过程问题
洛谷P2245 星际导航
I wrote some code in my resume, but I still can't pass the interview
Application of Identification Cryptography in IMS Network
[Likou] 22. Bracket generation
2022新员工公司级安全教育基础培训(118页)
ALSA音频架构
Apache初体验
嵌入式分享合集33
澳大利亚网络空间安全体系建设论析
[Note] Is the value of BatchSize the bigger the better?









