C/C++

Как удалить элемент массива в C++

Мне нужно удалить каждый 2ой элемент динамического массива не используя индексацию. Только указатели
#include <iostream>
#include <iomanip>
using namespace std;
void fill(int* box, const size_t n) {
auto begin = box;
const auto end = box + n;
cout << "Input " << n << " elements: ";
while (begin != end) {
cin >> *begin;
++begin;
}
}
void show(int* box, const size_t n) {
auto begin = box;
const auto end = box + n;
cout << "Elements: ";
while (begin != end) {
cout << *begin << ' ';
++begin;
}
puts("");
}
void squeeze(int* box, size_t& n) {
auto begin = box + 2;
const auto end = box + n;
auto m = n >> 1;
if (n & 1) ++m;
auto next = box + 1;
while (begin < end) {
*next = *begin;
++next;
begin += 2;
}
n = m;
}
void addresses(int* box, const size_t n) {
auto begin = box;
const auto end = box + n;
cout << "Addresses: ";
while (begin != end) {
if (!*begin) cout << setw(8) << setfill('0') << begin << ' ';
++begin;
}
puts("");
}
void replace(int* box, size_t& n, int x) {
auto begin = box;
const auto end = box + n;
while (begin != end) {
*begin = x;
++begin;
}
}
int main() {
cout << "Input n: ";
size_t n;
cin >> n;
auto m = new int[n];
fill(m, n);
show(m, n);
squeeze(m, n);
show(m, n);
replace(m, n, 0);
show(m, n);
cout << "Input k: ";
size_t k;
cin >> k;
addresses(m, k);
delete[] m;
system("pause > nul");
}
Марат Касаев
Марат Касаев
88 525
Лучший ответ