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;
}
Do'stlaringiz bilan baham: |