AXBOROT TEXNOLOGIYALARI UNIVERSITETI
RvaMA fakulteti 830-22 guruh talabasi
Eshqobilov Xushnudning
Ma’lumotlar Tuzilmasi va Algoritmlar fanidan
3-AMALIY ISHI
Bajardi:Eshqobilov Xushnud
Tekshirdi:Shoraimov Husanboy
TOSHKENT 2023
7.N ta elementdan tashkil topgan navbat berilgan.navbatning eng katta elementini o’chiring
#include
#include
int main() {
std::queue myQueue;
int n;
std::cout << "Queue elementlar sonini kiriting: ";
std::cin >> n;
std::cout << "Queue elementlarini kiriting: ";
for(int i = 0; i < n; i++)
{
int element;
std::cin >> element;
myQueue.push(element);
}
int maxElement=myQueue.front();
int queueSize = myQueue.size();
for(int i = 0; i < queueSize; i++) {
int frontElement = myQueue.front();
myQueue.pop();
if(frontElement > maxElement) {
maxElement = frontElement;
}
myQueue.push(frontElement);
}
for(int i = 0; i < queueSize; i++) {
int frontElement = myQueue.front();
if(frontElement != maxElement) {
myQueue.push(frontElement);
myQueue.pop();
}
}
std::cout << "Eng katta elementni o'chirgandan so'ng o'zgartirilgan navbat: ";
while(!myQueue.empty()) {
std::cout << myQueue.front() << " ";
myQueue.pop();
}
return 0;
}