2-TOPSHIRIQ
(19-variant)
Stek barcha elementi ochirilsin
#include
using namespace std;
void Chiqarish(stack yangi) {
while (!yangi.empty()) {
cout << yangi.top() << " ";
yangi.pop();
}
}
stack Ochirish(stack navbat, int oxiri) {
stack yangi;
while (!navbat.empty()) {
if (navbat.top() != oxiri) {
yangi.push(navbat.top());
}
navbat.pop();
}
return yangi;
}
int main() {
stack navbat;
navbat.push(5);
navbat.push(15);
navbat.push(35);
navbat.push(10);
navbat.push(10);
navbat.push(26);
navbat.push(10);
cout << "Oldin: ";
Chiqarish(navbat);
navbat = Ochirish(navbat, navbat.top());
cout << "\nKeyin: ";
Chiqarish(navbat);
return 0;
}
Dostları ilə paylaş: |