Swd022-L2-guruh talabasi Dehqonov Javohir. 5-labaratoriya 3-variant



Yüklə 372,63 Kb.
səhifə1/2
tarix18.05.2020
ölçüsü372,63 Kb.
#31204
  1   2
5-labaratoriya Dehqonov J.

SWD022-L2-guruh talabasi Dehqonov Javohir.

5-labaratoriya 3-variant



3)

  1. Yangi konteynerlar hosil qiling, uni standart funksiyalar yordamida elementlar bilan to’lating count funksiyasi yordamida amallar bajaring;

  2. Iteratorlardan foydalanib map konteyneri ustida amallar bajaring;

  3. fre () funksiyasidan foydalanib xotirani dinamik taqsimlashni amalga oshiring .

1)

#include

#include

#include

#include

#include

using namespace std;

int main()

{

//char va int toifasifa multimap



// Initsializator ro'yxati bilan boshlash

multimap mmapOfPos;

// mapga elementni kiritish

mmapOfPos.insert(std::pair('t', 9));

// Iterator yordamida multimap ustida takrorlanish

for (std::multimap::iterator it = mmapOfPos.begin();it != mmapOfPos.end(); it++)

cout << it->first << " :: " << it->second << endl;

cout << "***************************" << endl;

//count funksiyasidan foydalanish

int arr[] = { 14, 12, 15, 11, 10 };

//massivdan set ga initsializatsiya qilish

set s(arr, arr + 5);

// 11 ning bor yoki yo'qligini tekshirish

if (s.count(11))

cout << "set da 11 bor\n";

else


cout << "set da 11 yo'q\n";

// 18 bor yoki yo'qligini tekshirish

if (s.count(18))

cout << "set da 18 bor\n";



else

cout << "set da 18 yo'q\n";



return 0;}


2)

#include



#include

#include

using namespace std;

int main()

{

map gquiz1;



gquiz1.insert(pair(1, 40));

gquiz1.insert(pair(2, 30));

gquiz1.insert(pair(3, 60));

gquiz1.insert(pair(4, 20));

gquiz1.insert(pair(5, 50));

gquiz1.insert(pair(6, 50));

gquiz1.insert(pair(7, 10));

map::iterator itr;

cout << "\ngquiz1 mapi : \n";

cout << "\tKALIT\tELEMENT\n";

for (itr = gquiz1.begin(); itr != gquiz1.end(); ++itr) {

cout << '\t' << itr->first



<< '\t' << itr->second << '\n';

}


cout << endl;

map gquiz2(gquiz1.begin(), gquiz1.end());

cout << "\ngquiz2 mapidan keyin" << "gquiz1 ning nusxasi: \n";

cout << "\tKALIT\tELEMENT\n";

for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {

cout << '\t' << itr->first << '\t' << itr->second << '\n';

}

cout << endl;



cout << "\ngquiz2 kalit = 3 dan kam elementlarni olib tashlangandan keyin : \n";

cout << "\tKALIT\tELEMENT\n";

gquiz2.erase(gquiz2.begin(), gquiz2.find(3));

for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {

cout << '\t' << itr->first

<< '\t' << itr->second << '\n';

}


int num;

num = gquiz2.erase(4);

cout << "\ngquiz2.erase(4) : ";

cout << num << " removed \n";

cout << "\tKALIT\tELEMENT\n";

for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {

cout << '\t' << itr->first << '\t' << itr->second << '\n';

}


cout << endl;

cout << "gquiz1.lower_bound(5) : " << "\tKALIT = ";

cout << gquiz1.lower_bound(5)->first << '\t';

cout << "\tELEMENT = " << gquiz1.lower_bound(5)->second << endl;

cout << "gquiz1.upper_bound(5) : " << "\tKALIT = ";

cout << gquiz1.upper_bound(5)->first << '\t';

cout << "\tELEMENT = " << gquiz1.upper_bound(5)->second << endl;

return 0;



}



Yüklə 372,63 Kb.

Dostları ilə paylaş:
  1   2




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin