当前位置:网站首页>Inversion problem - key point
Inversion problem - key point
2022-07-31 10:18:00 【[email protected]】
Given a linear table, how to invert the elements in it?Two integer variables i and j can be set, i points to the first element, j points to the last element, while exchanging the elements pointed to by i and j, and let i and j move toward each other until they meet, the implementation code is as follows.Suppose the elements are stored in the array a[ ], and left and right are the subscripts of the elements at both ends of the array.
for(int i=lefft,j=right;i<j;i++,j--){int temp=a[i];a[i]=a[j];a[j]=temp;}【Example 2-5】
(1) Move the front k(k (2) Move the front k(k (3) Move the elements in the array (X0, X1, ..., Xn-1) tobecomes (Xp, Xp+1, ..., Xn-1, X0, X1,...,Xp-1), that is, circularly shifted left by p(0Only need to invert the entire array to satisfy the requirement that the front-end k elements are reversed and placed in the back-end of the arrayOnly need to invert the front-end k elements, and then invert the entire array to satisfy the front-end k elements in the original order and put them in the back end of the arrayOnly need to set 0~p-1 The element at the position is reversed, and then p~n-1Invert the elements of the position, and then invert the entire array.
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/212/202207311008455709.html
边栏推荐
- Principle of Redis Sentinel
- 解决rpc error: code = Unimplemented desc = method CheckLicense not implemented
- &#x开头的是什么编码?
- 第五章
- 浓眉大眼的谷歌 Chrome 也叛变了,教你一招快速清除其自带广告
- NowCoderTOP23-27 Binary tree traversal - continuous update ing
- 医院管理系统数据库,课程设计,SQLserver,纯代码设计
- Day113.尚医通:用户认证、阿里云OSS、就诊人管理
- Rich text editor Tinymce
- MySQL中JOIN的用法
猜你喜欢
随机推荐
Redis Cluster - Sentinel Mode Principle (Sentinel)
The fifth chapter
学习笔记——七周成为数据分析师《第二周:业务》:业务分析框架
双链表的创建
FCN中制作自己的数据集并进行训练
loadrunner-Controller负载测试-各模块功能记录01测试场景设计
Dart Log tool class
The big-eyed Google Chrome has also betrayed, teach you a trick to quickly clear its own ads
darknet 硬件软件环境的设置和检测
Mybaits Frequently Asked Questions Explained
Come n times - 07. Rebuild the binary tree
Three ways of single sign-on
centos7安装mysql5.7
Day113.尚医通:用户认证、阿里云OSS、就诊人管理
Chapter VII
使用turtle画按钮
SQL——左连接(Left join)、右连接(Right join)、内连接(Inner join)
SQL力扣刷题七
【LeetCode】383.赎金信
GZIPInputStream 类源码分析









