Guruh Tajriba ishi №3 Mavzu: stl kutubxonalari. Chizikli konteynerlar (array, vector, deque, list, forward list) Ishning maqsadi


Download 0.71 Mb.
bet2/2
Sana30.04.2023
Hajmi0.71 Mb.
#1416798
1   2
Bog'liq
i Shavqidinov Abdulla 3-lab

Chiziqli konteynerlarni turlari:

  • array - statik doimiy massiv;

  • vector – dynamik doimiy massiv;

  • deque - ikki tomonlama navbat;

  • forward_list - bog'langan ro'yxat;

  • list – ikki tomonlama bog'langan ro'yxat.

1-topshiriq
Navbat o‘rtasiga '+' belgi joylashtirilsin.
#include
#include
using namespace std;

int main()


{
// Empty Queue
queue myqueue;
myqueue.push(3);
myqueue.push(5);
myqueue.push(7);
myqueue.push(60);
myqueue.push(66);
myqueue.push(81);

// Printing content of queue


while (!myqueue.empty()) {
cout << '+' << myqueue.front();
myqueue.pop();
}
}






2-topshiriq
Ro’yxat berilgan ekrandan kirtilgan sonning toq qiymatdagi elementlarini ekranga chiqaring.

#include
using namespace std;
int main()
{
list l;
int n;
cout << "Ro'yxatdagi elementlar sonini kiriting: ";
cin >> n;
cout << "Ro'yxat elementlarini kiriting:\n";
for(int i = 1; i <= n; i ++)
{
int x;
cin >> x;
l.push_back(x);
}
cout << "Toq qiymatdagi elementlar:\n";
while(l.size())
{
if(l.back() % 2 == 1)
cout << l.back() << ' ';
l.pop_back();
}
}





3-topshiriq
Ro’yxatni juft sonlarini chiqaradigan dastur tuzing

#include


#include
using namespace std;
void view(stack my)
{
while(!my.empty())
{
cout<my.pop();
}
}
int main() {
stack my,my1;
int n,x;
cout<<"Satckni o'lchamini kiriting: "; cin>>n;
for(int i=1; i<=n; i++)
{
cin>>x;
my.push(x);
}
cout<<"Hosil bo'lgan stack\n";
view(my);
for(int i=1; i<=n; i++)
{
x=my.top();
if(i%2==1)
my1.push(x);
my.pop();
}
cout<<"\nJut elemtlari olingan steck: \n";
view(my1);
}



4-topshiriq
Navbat o‘rtasidagi element o‘chirib tashlansin. Agar navbat elementlari soni toq bo‘lsa, bitta element, aks holda ikkita element o‘chirilsin.
#include
#include
using namespace std;

int main()


{
int n;
cin>>n;
int k;
vector v1;
for(int i=0; i{
cin>>k;
v1.push_back(k);
}
int a,b;
if(n%2==0)
{
a=n/2;
b=a+1;
for(int i=0; i{
if(i!=(a-1) && i!=(b-1))
{
cout<}
}
}
else
{
a=n/2;
for(int i=0; i{
if(i!=a)
{
cout<}
}
}

return 0;


}



Download 0.71 Mb.

Do'stlaringiz bilan baham:
1   2




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