Как я могу переместить элементы в массиве к следующему элементу
eg: x[5] = { 5, 4, 3, 2, 1 }; // initial values
x[0] = 6; // new values to be shifted
x[5] = { 6, 5, 4, 3, 2 }; // shifted array, it need to be shifted,
// not just increment the values.
Это то, что я сделал до сих пор. Это неправильно, поэтому мне нужна помощь здесь. Заранее спасибо.
#include <iostream>
using namespace std;
int main()
{
int x[5] = { 5, 4, 3, 2, 1 };
int array_size = sizeof(x) / sizeof(x[0]);
x[0] = 6;
int m = 1;
for(int j = 0; j < array_size; j++) {
x[m+j] = x[j];
cout << x[j] << endl;
}
return 0;
}