|
Guruh talabasi Omonbayev Jaloliddin Mavzu
|
tarix | 04.01.2023 | ölçüsü | 25,8 Kb. | | #78403 |
| 5. Dinamik MT
911-21 guruh talabasi Omonbayev Jaloliddin
Mavzu: Dinamik MT.
Stek o’rtasidagi element o’chirib tashlansin. Agar stek elementi toq bo’lsa, bitta element, aks holda ikkita element o’chirilsin.
#include
#include
using namespace std;
int main(){
int n; cin>>n;
stack s;
for(int i=0; i {
int x; cin>>x;
s.push(x);
}
int c,t;
stack s2;
if(n%2==0)
{
c=(n/2); t=(n/2)+1;
int z=1;
while(!s.empty())
{
if(z!=c and z!=t)
{
int r=s.top();
s2.push(r);
}
z++;
s.pop();
}
}else{
t=(n/2)+1;
int z=1;
while(!s.empty())
{
if(z!=t)
{
int r=s.top();
s2.push(r);
}
z++;
s.pop();
}
}
while(!s2.empty())
{
cout< s2.pop();
}
}
Ro’yhat har ikkinchi elementi o’chirilsin.
#include
#include
using namespace std;
int c=0;
bool even(const int& value)
{
c++;
return (c%2)==0;}
int main()
{
list l{1,2,3,4,5};
l.remove_if(even);
list::iterator it;
for(it = l.begin(); it!=l.end(); it++)
{
cout<<*it<<' ';
}
return 0;}
Dostları ilə paylaş: |
|
|