当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
让动画每次重复前都有延迟
Redis Cluster - Sentinel Mode Principle (Sentinel)
Summary of three methods for SQL deduplication
踩水坑2 数据超出long long
loadrunner脚本--添加集合点
NowCoderTOP17-22 Binary search/sort - continuous update ing
sql中 exists的用法
loadrunner脚本--添加事务
Qt 编译错误:C2228: “.key”的左边必须有类/结构/联合
NowCoderTOP28-34 binary tree - continuous update ing
win10镜像下载
【职场杂谈】售前工程师岗位的理解杂谈
Business-(Course-Chapter-Subsection) + Course Publishing Some Business Ideas
Meikle Studio--Hongmeng 14-day development training notes (8)
开放麒麟 openKylin 自动化开发者平台正式发布
【LeetCode】1161.最大层内元素和
力扣shell刷题
Rich text editor Tinymce
GVINS论文阅读笔记
如何将虚拟机上的文件复制到主机上









