Masala sharti: Ro’yxatdagi eng kichik elementini toping. Code


Download 29.1 Kb.
Sana23.04.2023
Hajmi29.1 Kb.
#1392308
Bog'liq
Dasturlash

Muhammad al-xorazmiy nomida


Toshkent Axborot Texnalogiyalari univarsiteti
224-22 guruh talabasi
Ahmadjonov Abduvohidning
Dasturlash_2 fanidan bajargan Mustaqil ishi

Topshirdi: Ahmadjonov Abduvohid


Qabul qildi: Aliqulov Akmal

Masala sharti: Ro’yxatdagi eng kichik elementini toping.

Code: #include
#include
using namespace std;

int findMin(list lst) {


int min = lst.front();
for (auto it = lst.begin(); it != lst.end(); it++) {
if (*it < min) {
min = *it;
}
}
return min;
}

void printList(list lst) {


for (auto it = lst.begin(); it != lst.end(); it++) {
cout << *it << " ";
}
cout << endl;
}

int main() {


list lst;
int size;
cout << "Ro'yxat hajmini kiriting: ";
cin >> size;

for(int i = 0; i < size; i++) {


cout << "Iltimos, " << i+1 << "-sonni kiriting: ";
int num;
cin >> num;
lst.push_back(num);
}

cout << "\nRo'yxat: ";


printList(lst);

int min = findMin(lst);


cout << "\nEng kichik element: " << min << endl;

return 0;


}

Masala sharti: Navbat o‘rtasidagi element o‘chirib tashlansin. Agar navbat elementlari soni toq bo‘lsa, bitta element, aks holda ikkita element o‘chirilsin
Code: #include
#include

using namespace std;

void removeMiddle(deque& nums) {
int n = nums.size();
if (n % 2 == 1) {
nums.erase(nums.begin() + n/2);
} else {
int idx = n/2 - 1;
nums.erase(nums.begin() + idx);
nums.erase(nums.begin() + idx);
}
}

int main() {


deque nums;

int n;
cout << "list uzunligini kiriting: ";


cin >> n;

for (int i = 0; i < n; i++) {


cout << "Iltimos, " << i+1 << "-sonni kiriting:";
int num;
cin >> num;
nums.push_back(num);
}

cout << "Deque: ";


for (auto num : nums) {
cout << num << " ";
}
cout << endl;
removeMiddle(nums);
cout << "Qolgan sonlar: ";
for (auto num : nums) {
cout << num << " ";
}
cout << endl;

return 0;


}

Download 29.1 Kb.

Do'stlaringiz bilan baham:




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