21. Stek oxirgi elementiga teng barcha elementlar o‘chirilsin



Download 22,34 Kb.
Sana17.08.2021
Hajmi22,34 Kb.
#149881
Bog'liq
dek,stak


21. Stek oxirgi elementiga teng barcha elementlar o‘chirilsin.

#include

#include

using namespace std;

void Chiqarish(stack yangi) {

while (!yangi.empty()) {

cout << yangi.top() << " ";

yangi.pop();

}

}

stack Ochirish(stack navbat, int oxiri) {



stack yangi;

while (!navbat.empty()) {

if (navbat.top() != oxiri) {

yangi.push(navbat.top());

}

navbat.pop();



}

return yangi;

}

int main() {



stack navbat;

navbat.push(5);

navbat.push(15);

navbat.push(35);

navbat.push(10);

navbat.push(10);

navbat.push(26);

navbat.push(10);

cout << "Oldin: ";

Chiqarish(navbat);

navbat = Ochirish(navbat, navbat.top());

cout << "\nKeyin: ";

Chiqarish(navbat);

return 0;

}

/Stek birinchi va oxirgi elementlari o‘rni almashtirilsin

#include

using namespace std;

void rev(stack&x){

int sz=x.size(),mytop,mybottom;

mytop=x.top();

x.pop();

int tmp[sz-1],i=0;

while(!x.empty()){

mybottom=x.top();

tmp[i++]=mybottom;

x.pop();


}

stack returnIt;

returnIt.push(mybottom);

for(i=0;i<=sz-3;i++){

returnIt.push(tmp[i]);

}

returnIt.push(mytop);



while(!returnIt.empty()){

int tt=returnIt.top();

x.push(tt);

returnIt.pop();

}

}

int main() {



stackx;

x.push(1);

x.push(2);

x.push(3);

x.push(4);

x.push(5);

stacky=x;

cout<<"O‘rin almashishdan oldin: ";

while(!y.empty()){

int tt=y.top();

cout<

y.pop();


}

rev(x);


cout<<"\nO‘rin almashgandan keyin : ";

while(!x.empty()){

cout<

x.pop();


}

return 0;

}

6.Stekning eng kichik elementi topilsin va undan keyin 0 joylashtirilsin.

#include
#include
using namespace std;
int main() {
stack st, nw;
int n,min=0;
cout<<"N = ";
cin>>n;
for(int i=0; i
int temp;
cin>>temp;
if(i == 0 || temp < min) min = temp;
st.push(temp);
}
while(!st.empty()) {
if( (st.top() == min) )
nw.push(0);
nw.push(st.top());
st.pop();
}
while(!nw.empty()) {
cout<
nw.pop();
}
return 0;
}

Natija: 45 12 5 1 3

45 12 5 0 1 3

Navbat o‘rtasiga '+' belgi joylashtirilsin.

#include

#include

using namespace std;

queue Qidirish(queue navbat) {

int a = navbat.size() / 2, n = 0;

queue yangi;

while (!navbat.empty()) {

n ++;

cout << navbat.front() << " ";



yangi.push(navbat.front());

if (n == a) {

yangi.push("+");

}

navbat.pop();



}

return yangi;

}

void Chiqarish(queue navbat) {



while (!navbat.empty()) {

cout << navbat.front() << " ";

navbat.pop();

}

}



int main() {

queue navbat;

cout << "";

navbat.push("Abdukarimova");

navbat.push("Shoira");
cout << "Oldin: ";

navbat = Qidirish(navbat);

cout << "\nKeyin: ";

Chiqarish (navbat);

}

Dekdagi manfiy sonlarni o’chiring.

#include

#include

using namespace std;

int main()

{

int val[10] = {7,2,-3,8,-6,4, 5, -2, 1,5};



deque dq;

for(int i(0); i < 10; ++i)

dq.push_back(val[i]);

deque::iterator iter(dq.begin());

while(iter != dq.end())

{

if(*iter < 0)



dq.erase((++iter) - 1);

else


++iter;

}

iter = dq.begin();



while(iter != dq.end())

{

cout<< *iter;



++iter; }

return 0; }



7.Dekni o’rtasidagi “dek”so’zini kiriting. .

#include #include

using namespace std; int main() {

int i,n; string tmp;

deque s; deque :: iterator it;

cout<<"Nechta so`z kiritmoqchisiz? :"; cin>>n;

cout<

cin>>tmp; s.push_back(tmp);

}

if(n%2==0) {



n/=2; s.insert(s.begin()+n,"dek");

} else {


n/=2; s.insert(s.begin()+n,"dek"); n+=1;

s.insert(s.begin()+n,"dek");

}

for(it=s.begin(); it!=s.end(); ++it) { cout<<*it<<" ";



}

s.clear(); return 0;



}

Download 22,34 Kb.

Do'stlaringiz bilan baham:




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish