(指针)n个整数,将最后m个数变成最前面m个数

xiaoxiao2021-02-28  16

#include<cstdio> #include<iostream> #include <cmath> #include<string> #include<algorithm> #include<set> #include<queue> #include<iterator> #include<cstring> using namespace std; void move(int a[], int n, int m) { int *p, aend; aend = a[n-1]; for(p=a+n-1; p>a; p--) *p = *(p-1); *a = aend; m--; if(m>0) move(a, n, m); } int main() { printf("请输入整数数量:"); int n; cin >> n; printf("请输入数组内容:"); int i, a[10000], m; for(i=0; i<n; i++){ cin >> a[i]; } printf("请输入后移几位:"); cin >> m; move(a, n, m); printf("排好序的整数:"); for(i=0; i<n; i++){ cout << " " << a[i]; } cout << "\n"; return 0; }
转载请注明原文地址: https://www.6miu.com/read-450042.html

最新回复(0)