数组元素循环右移及静态链表

本文介绍了一种不使用额外数组而通过改变打印输出顺序来实现数组元素循环右移的方法。这种方法适用于不需要实际移动数组元素的情况,仅需按循环右移后的顺序输出数组元素。

1. 静态链表

https://github.com/BodhiXing/Data_Structure

2. 数组元素循环右移

https://pta.patest.cn/pta/test/17/exam/4/question/262

思路:不做循环,只是换方式打印输出。

 1 #include <stdio.h>
 2 #include <math.h>
 3 
 4 
 5 int main() {
 6     int n,m,i;
 7     scanf("%d %d",&n,&m);
 8     int a[n];
 9     for(i=0; i<n; i++)
10         scanf("%d",&a[i]);
11     //M>N
12     while(m>=n)
13         m %= n;
14     for(i=n-m; i<n; i++)
15         printf("%d ",a[i]);
16     for(i=0; i<n-m-1; i++) {
17         printf("%d ",a[i]);
18     }
19     //注意:序列结尾不能有多余空格 
20     printf("%d",a[i]);
21     return 0;
22 }

 

转载于:https://www.cnblogs.com/boyiliushui/p/6119699.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值