Deque oxirgi 5 ta elementlarini o’chirilsin


Download 30.4 Kb.
Sana04.04.2023
Hajmi30.4 Kb.
#1327852

Deque oxirgi 5 ta elementlarini o’chirilsin.
#include
#include
using namespace std;

void removeLastFive(deque &d)


{
int n = d.size();
if (n <= 5)
{
d.clear();
}
else
{
for (int i = 0; i < 5; i++)
{
d.pop_back();
}
}
}

int main()


{
deque d{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
removeLastFive(d);
while (!d.empty())
{
cout << d.front() << " ";
d.pop_front();
}
cout << endl;
return 0;
}


Ro’yxat berilgan ekrandan kirtilgan sonning toq qiymatdagi elementlarini ekranga chiqaring.
#include
#include
#include
using namespace std;

int main()


{
srand(time(0));
int n, j = 0;
cout << "Ro'yhat elementlari soni: ";
cin >> n;
list a;
for (int j = 0; j < n; j++)
{
a.push_back(rand() % 50 - 20);
}
for (auto i = a.begin(); i != a.end(); i++)
{
cout << *i << " ";
}
cout << endl;
for (auto i = a.begin(); i != a.end(); i++)
{
if (*i % 2 != 0)
{
cout << *i << " ";
}
}
cout << endl;
_getwch();
return 0;
}



Download 30.4 Kb.

Do'stlaringiz bilan baham:




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