Toshkent – 2023 14-variant:
Stek ortasidagi element ochirib tashlansin. Agar stek elementi toq bolsa, bitta element, aks holda ikkita element ochirilsin.
#include #include
void removeMiddle(stack& s, int curr) {
// stek o‘rtasidagi elementni ochirish
if (s.size() == (curr+1)/2) {
s.pop();
return;
}
// stek ichidagi boshqa elementlar uchun
int x = s.top();
s.pop();
removeMiddle(s, curr);
s.push(x);
}