Files
exam_code_for_408/2010_code_circle_leftmove.cpp
2021-12-01 16:31:05 +08:00

25 lines
507 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include<stdio.h>
#include<stdlib.h>
void reverse(int a[], int start, int end) {
//逆置startend之间的所有数
int i = 0;
while (start + i < end - i) {
int tmp = a[start + i];
a[start + i] = a[end - i];
a[end - i] = tmp;
i++;
}
}
void move(int a[], int p, int length) {
reverse(a, 0, p - 1);
reverse(a, p, length - 1);
reverse(a, 0, length - 1);
}
int main() {
int a[] = { 1,2,3,4,5,6,7,8,9,10 };
move(a, 7, 10);
return 0;
}