数组顺序颠倒——递归方法

#include<bits/stdc++.h>
using namespace std;
void reverse(int *A, int lo,int hi){
	if(lo<hi)
	
	{
		swap(A[lo],A[hi]);
		reverse(A,lo+1,hi-1);
	}
}
//验证
int main(){
	int A[]={0,1,2,3,4};
	reverse(A,0,4);
	for(int i=0;i<5;i++)
	cout<<A[i]<<" ";
	cout<<endl;
}
上一篇:牛客网HJ11 数字颠倒Python3 解法


下一篇:2021-09-04