Skip to content
On this page

ds00_reverse.cpp

cpp
#include <iostream>
#include <vector>
using namespace std;
void reverse(vector<int> &v, int a, int b) {
    // write your code only in this function
    int mid = (a + b) / 2;

    for (int i = a; i <= mid; i++) {
        // generated by copilot
        int temp = v[i];
        v[i] = v[b - (i - a)];
        v[b - (i - a)] = temp;
    }
}

int main() {
    // read input
    int n, a, b;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int c;
        cin >> c;
        v.push_back(c);
    }
    cin >> a >> b;
    // call function
    reverse(v, a, b);
    // display content of the vector
    for (auto &x : v) cout << x << " ";
    cout << endl;
}

See on GitHub

Last Updated: 15/1/2567 13:25:21 (UTC+7)

Released under the MIT License