[アルゴリズム]配列を逆さ

アルゴリズムの複雑さはO(n)
、nの問題の規模は、n 2は、問題の大きさに分割し、同じ形状を有しています

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
void reverse(int* A, int low, int high)
{
    if (low < high)
    {
        swap(A[low], A[high]);
        reverse(A, low + 1, high - 1);
    }
}
int main()
{
    int A[10] = { 1,2,3,4,5,6,7,8,9,10 };
    reverse(A, 0, 9);

    for (auto a : A)
    {
        cout << a << " ";
    }
    cout << endl;
    cout << "hello world" << endl;
    return 0;
}

おすすめ

転載: www.cnblogs.com/tailiang/p/11730274.html