当前位置:网站首页>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"
边栏推荐
- async(异步)和await的使用
- 网络技能树
- Switch---Spanning Tree---Three-layer Architecture Summary
- Self-research capability was recognized again, and Tencent Cloud Database was included in the Forrester Translytical report
- 洛谷P2245 星际导航
- The sword refers to offer_abstract modeling capabilities
- AVH 动手实践 (二) | 在 Arm 虚拟硬件上部署 PP-OCR 模型
- 剑指offer_抽象建模能力
- 一起Talk编程语言吧
- 北湖区燕泉街道开展“戴头盔·保安全”送头盔活动
猜你喜欢

0 Basic software test for career change, self-study for 3 months, 12k*13 salary offer

0基础转行软件测试,自学3个月,浅拿12k*13薪offer

优化是一种习惯●出发点是“站在靠近临界“的地方

Jetson Orin平台4-16路 GMSL2/GSML1相机采集套件推荐

自研能力再获认可,腾讯云数据库入选 Forrester Translytical 报告

嵌入式分享合集33

CAD2020 打开错误报告 e06d7363h Exception at 13644F69h

IP-Guard如何禁止运行U盘程序

Word2021 中的图片保存后就变模糊了

视觉任务种常用的类别文件之一json文件
随机推荐
《卫星界》刊评“星辰大海”计划:孙宇晨为太空旅游带来新的机遇
如何将360全景图导出高清短视频分享到视频平台上?
1815. Get the maximum number of groups of fresh donuts state compression
洛谷P4032 火锅盛宴
交换机和路由器技术-21-RIP路由协议
Research on a Consensus Mechanism-Based Anti-Runaway Scheme for Digital Trunking Terminals
[Actual combat scene] Mall-discount event design plan
Self-research capability was recognized again, and Tencent Cloud Database was included in the Forrester Translytical report
Three 】 【 yolov7 series of actual combat from 0 to build training data sets
标识密码技术在 IMS 网络中的应用
交换机和路由器技术-35-NAT转PAT
Australia cyberspace security system construction
Mysql中事件和定时任务
Bubble sort and heap sort
Resize() usage row pit in vector
关于数据分页显示
FPGA工程师面试试题集锦111~120
使用百度EasyDL实现施工人员安全装备检测
[Server installation mysql] Use mysql offline installation package to install mysql5.7 under centos7
Harvesting of radio frequency energy