Dasturlash II


Download 117.15 Kb.
Sana22.04.2023
Hajmi117.15 Kb.
#1382543

O'zbekiston Respublikasi Axborot texnologiyalari
va kommunikatsiyalarini rivojlantirish vazirligi.
Muhammad al-Xorazmiy nomidagi Toshkent
axborot texnologiyalari universiteti
DASTURLASH II

2-Laboratoriya ishi

Bajaruvchi: Mansurov Sharofiddin




1-Topshiriq
10. Birinchi elementni har qanday turdagi elementlari uchun ro‘yxatdan olib tashlaydigan funksiyani yozing.
#include
#include
using namespace std;


void removeFirstElement(list& lst) {
if (!lst.empty()) {
lst.erase(lst.begin());
}
}


int main() {
list lst = {3,1,10, 15, 20, 25};
cout << "Ro'yhatning boshlang'ich hollari: ";
for (auto x : lst) {
cout << x << " ";
}
cout << endl;


removeFirstElement(lst);


cout << "Ro'yhatning o'zgarishdan keyin hollari: ";
for (auto x : lst) {
cout << x << " ";
}
cout << endl;


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();
}
system("pause");


return 0;
}
Natija:

Download 117.15 Kb.

Do'stlaringiz bilan baham:




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