Shifting an array in C++

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int arr_size = 5;
    int arr[arr_size] = {6, 7, 8, 9, 2};
    int num_shifts = 2;
    rotate(arr, arr + num_shifts, arr + arr_size);

    for (int i = 0; i < arr_size; i++)
    {
        cout << arr[i] << " ";
    }
    cout << endl;

    return 0;
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *