Xidoyatov Abdullaning Dasturlash 2 fanidan 2-labaratoriya topshiriqlari


Download 30.24 Kb.
Sana30.04.2023
Hajmi30.24 Kb.
#1402327
Bog'liq
Xidoyatov Abdullaning Dasturlash 2 fanidan labaratoriya


Xidoyatov Abdullaning Dasturlash 2 fanidan
2-labaratoriya topshiriqlari


Navbat eng kichik elementi o‘chirilsin.

#include
#include
using namespace std;

int main() {


int n; // queue uzunligi
cin >> n;
queue q; // queue yaratish
int min_element = INT_MAX; // eng kichik elementni topish uchun o'zgaruvchi
for (int i = 0; i < n; i++) {
int x;
cin >> x; // qiymat kiritish
q.push(x); // qiymatni queue'ga qo'shish
if (x < min_element) {
min_element = x; // eng kichik elementni topish
}
}
while (!q.empty()) {
if (q.front() == min_element) {
q.pop(); // eng kichik elementni o'chirish
break;
} else {
q.push(q.front()); // eng kichik element emas, uni oxiridan boshiga ko'chirish
q.pop();
}
}
n--; // queue uzunligini kamaytirish
while (!q.empty()) {
cout << q.front() << " "; // yangi queue'ni ekranga chiqarish
q.pop();
}
return 0;
}

Download 30.24 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling