4-laboratoriya ishi
№5 variant
Topshiriq №1
1
Navbat eng kichik elementi topilsin va undan keyin 0 joylashtirilsin.
Dastur kodi:
#include
#include
using namespace std;
int main()
{
queue qu;
queue qu2;
int n;
cout<<"Navbat elementlari sonini kiriting:";
cin >> n;
cout<<"Navbat elementlarini kiriting:";
for(int i=0, a; i
{
cin >> a;
qu.push(a);
qu2.push(a);
}
const int& k = qu2.front();
int min = k;
for(int i=0; i
{
if(qu2.front() < min) min = qu2.front();
qu2.pop();
}
cout << "min=" << min << endl;
for(int i=0; i
{
if(qu.front() == min)
{
qu2.push(qu.front());
qu2.push(0);
qu.pop();
continue;
}
qu2.push(qu.front());
qu.pop();
}
n = qu2.size();
for(int i=0; i
{
cout << qu2.front() << " "; qu2.pop();
}
}
Natijasi: