Muhammad Al-Xorazmiy nomidagi
Toshkent Axborot Texnologiyalari Universiteti
Radioelektron qurilmalar va tizimlar yoʻnalishi talabasi
Patxillayeva Sevaraning Dasturlash fanidan
2-topshirig'i
Tekshirdi: Aliqulov Akmal
Topshirdi: Patxillayeva Sevara
10 Birinchi elementni har qanday turdagi elementlari uchun ro‘yxatdan olib tashlaydigan funksiyani yozing
Kodi:
#include
#include
using namespace std;
template
void removeFirstElement(std::list&myList) {
if(!myList.empty()) {
myList.pop_front();
}
}
int main() {
std::listmyIntList ={1,2,3,4,5};
std::listmyDoubleList = {1.23, 4.56, 7.89};
std::listmyStringList = {"olma", "banan", "olcha"};
removeFirstElement(myIntList);
removeFirstElement(myDoubleList);
removeFirstElement(myStringList);
for (int i: myIntList){
std::cout<
}
std::cout<
for (double d: myDoubleList){
std::cout<
}
std::cout<
for (std:: string s : myStringList){
std::cout<
}
std::cout<
return 0;
}
10.2 Stek ning eng katta elementini topish va undan keyn 0 joylashtirilsin
Kodi:
#include
#include
using namespace std;
int main() {
stack s;
s.push(5);
s.push(7);
s.push(3);
int max = s.top();
while (!s.empty()) {
int current = s.top();
if (current > max) {
max = current;
}
cout << current << " ";
s.pop(); }
s.push(0);
cout << endl << "Eng katta element: " << max << endl;
cout << "Stekning yangi holati: ";
while (!s.empty()) {
cout << s.top() << " ";
s.pop();
}
cout << endl;
return 0;
}
Do'stlaringiz bilan baham: |