#include<iostream>
using namespace std;
void LeftMove(const int len, int *const Arr, const int length);
void RightMove(const int len, int *const Arr, const int length);
void Printf(const int * const Arr,const int len);
int main()
{
int Arr[10] = {12,23,34,45,56,67,78,89,90,100};
int len = sizeof(Arr) / sizeof(Arr[0]);
//LeftMove(len, Arr, 2);
RightMove(len,Arr,2);
}
void LeftMove(const int len, int *const Arr, const int length)
{
for (int i = 0; i < length; ++i)
{
int temp = Arr[0];
for (int j = 0; j < len - 1; ++j)
{
Arr[j] = Arr[j + 1];
}
Arr[len - 1] = temp;
}
Printf(Arr, len);
cout << endl;
}
void RightMove(const int len, int *const Arr, const int length)
{
for (int i = 0; i < length; ++i)
{
int temp = Arr[len-1];
for (int j = len-1; j >0 ; --j)
{
Arr[j] = Arr[j - 1];
}
Arr[0] = temp;
}
Printf(Arr, len);
}
void Printf(const int * const Arr, const int len)
{
for (int i = 0; i < len; i++)
{
cout << Arr[i];
}
}
数组位移操作
最新推荐文章于 2023-08-29 23:11:51 发布