I use Dev-c ++. My code works as it should, but in the steppe the code does not work and gives an error:
Failed test # 2. Runtime error main: malloc.c: 2406: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size)> = MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0) 'failed. Aborted (core dumped)
What is the reason? Not going beyond the array?
#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector <int> a(n); //ввод for (int i=0; i<n; i++) { cin >> a[i]; } //обработка int mem=a[n-1]; //сохранение последнего элемента вектора for (int i=n; i!=0; i--) { // массив сдвигается с конца swap(a[i],a[i-1]); // сдвиг вправо на 1 элемент } a[0]=mem; // замещение первого элемента последним до сдвига //вывод for (int i=0; i<n; i++) { cout << a[i] << " "; } }