O'zbekiston Respublikasi Axborot texnologiyalari
va kommunikatsiyalarini rivojlantirish vazirligi.
Muhammad al-Xorazmiy nomidagi Toshkent
axborot texnologiyalari universiteti
2-Laboratoriya ishi
Tekshiruvchi :SHodmon SHoyimovich
1-Topshiriq
10. Birinchi elementni har qanday turdagi elementlari uchun ro‘yxatdan olib tashlaydigan funksiyani yozing.
#include
#include
#include
using namespace std;
int main() {
srand(time(NULL));
int n, x;
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;
auto nx = next(a.begin(), 0);
a.remove(*nx);
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
_getwch();
return 0;
}
NAtija:
2-Topshiriq
10
|
Stek eng katta elementi topilsin va undan keyin 0 joylashtirilsin
|
#include
#include
#include
using namespace std;
int main()
{
srand(time(NULL));
stack stk1;
stack stk2;
int n,k;
cout << "n=";
cin >> n;
int katta;
for (int i = 0; i < n; i++)
{
k=rand()%45 - 30;
stk1.push(k);
cout<
}
cout<
katta=stk1.top();
while(!stk1.empty()){
k=stk1.top();
stk2.push(k);
if(k>katta)
katta=k;
stk1.pop();
}
while(!stk2.empty()){
k=stk2.top();
stk1.push(k);
cout<
if(k==katta){
stk1.push(0);
cout<<0<<" ";}
stk2.pop();
}
return 0;
}
Natija:
Dostları ilə paylaş: |