Tekshirdi: Rustamova Mohichehra


Download 0.67 Mb.
Sana11.05.2023
Hajmi0.67 Mb.
#1454171
Bog'liq
Дастурлаш


Muhammad Al-Xorazmiy nomidagi Toshkent Axborot Tehnologiyalar Universiteti Televizion Tehnologiyalar fakulteti SWD011-3 guruh talabasi Abdumavlonov Baxtjon

Tekshirdi:Rustamova Mohichehra

2-Variant



#include


#include

void deleteMiddle(std::queue& q) {


int n = q.size();
int mid = n / 2;
if (n % 2 == 0) {
q.pop();
mid--;
}
std::queue temp;
for (int i = 0; i < mid; i++) {
temp.push(q.front());
q.pop();
}
q.pop();
while (!temp.empty()) {
q.push(temp.front());
temp.pop();
}
}

int main() {


std::queue q;
q.push(1);
q.push(2);
q.push(3);
q.push(4);
q.push(5);
std::cout << "Before deletion: ";
while (!q.empty()) {
std::cout << q.front() << " ";
q.pop();
}
std::cout << std::endl;

deleteMiddle(q);

std::cout << "After deletion: ";
while (!q.empty()) {
std::cout << q.front() << " ";
q.pop();
}
std::cout << std::endl;

return 0;


}




#include


#include

void deleteEqual(std::priority_queue& pq) {


int first = pq.top();
while (!pq.empty() && pq.top() == first) {
pq.pop();
}
}

int main() {


std::priority_queue pq;
pq.push(5);
pq.push(2);
pq.push(5);
pq.push(1);
pq.push(5);

std::cout << "Before deletion: ";


while (!pq.empty()) {
std::cout << pq.top() << " ";
pq.pop();
}
std::cout << std::endl;

deleteEqual(pq);

std::cout << "After deletion: ";
while (!pq.empty()) {
std::cout << pq.top() << " ";
pq.pop();
}
std::cout << std::endl;

return 0;


}

Download 0.67 Mb.

Do'stlaringiz bilan baham:




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