数组循环位移

分治逆向

 

#include <iostream> using namespace std; char test[] = {'t','e','s','t','1','2','3','4'}; void Reverse(char *arr, int b, int e) { for ( ; b<e; b++,e--) { char tmp=' '; tmp = arr[e]; arr[e] = arr[b]; arr[b] = tmp; } } void RightShift(char *arr, int N, int k) { k%=N; Reverse(arr,0,N-k-1); Reverse(arr,N-k,N-1); Reverse(arr,0,N-1); } void main() { cout << test << endl; RightShift(test,8,4); cout << test << endl; } 

 

 

 

你可能感兴趣的:(数组循环位移)