翻转一个数组(c++实现)

反转一个数组:

其实STL中的vector有一个reverse函数便可以使用。

#include<iostream>
using namespace std;
int* ReverseArray(int*orig,unsigned short int b)
{
unsigned short int a=;
int swap;
for(a;a<--b;a++) //increment a and decrement b until they meet eachother
{
swap=orig[a]; //put what's in a into swap space
orig[a]=orig[b]; //put what's in b into a
orig[b]=swap; //put what's in the swap (a) into b
}
return orig; //return the new (reversed) string (a pointer to it)
} int main()
{
const unsigned short int SIZE=;
int ARRAY[SIZE]={,,,,,,,,,};
int*arr=ARRAY;
for(int i=;i<SIZE;i++)
{
cout<<arr[i]<<' ';
}
cout << endl;
arr=ReverseArray(arr,SIZE);
for(int i=;i<SIZE;i++)
{
cout<<arr[i]<<' ';
}
cout<< endl; return ;
}

结果:

翻转一个数组(c++实现)

上一篇:myBatis执行测试批量删除,出现测试类正常显示,但数据库数据没变


下一篇:五、使用druid管理数据库,mybatis连接mysql数据库