O’zbekistonRespublikasiAxborot Texnologiyalari va Kommunikatsiyalarini


Download 0.81 Mb.
Sana14.04.2023
Hajmi0.81 Mb.
#1358177
Bog'liq
Stek o‘rtasidagi element o‘chirib tashlansin. Agar stek elementi


O’zbekistonRespublikasiAxborot
Texnologiyalari va Kommunikatsiyalarini
RivojlantirishVazirligi

Muhammad Al-XorazmiyNomidagi Toshkent


AxborotTexnologiyalariUniversiteti

Variant 14:


Bajardi:Mamaraimov Elyor
Tekshirdi: Saidov.S



14

Stek o‘rtasidagi element o‘chiribtashlansin. Agar stek elementitoqbo‘lsa, bitta element, aksholdaikkita element o‘chirilsin.

#include
#include
usingnamespacestd;
voiddeleteMid_util(stack&s, intsizeOfStack, intcurrent)
{
if(current==sizeOfStack/2)
{
s.pop();
return;
}
intx = s.top();
s.pop();
current+=1;
deleteMid_util(s,sizeOfStack,current);
s.push(x);
}
voiddeleteMid(stack&s, intsizeOfStack)
{
deleteMid_util(s,sizeOfStack,0);
}
intmain()
{
stackst;
st.push('1');
st.push('2');
st.push('3');
st.push('4');
st.push('5');
st.push('6');
st.push('7');
st.push('8');
deleteMid(st, st.size());
while (!st.empty())
{
charp=st.top();
st.pop();
cout<}
return0;
}



#include
#include
#include
#include

usingnamespacestd;


voiddeleteMid_util(stack&s, intsizeOfStack)


{
intm = sizeOfStack / 2;
stackst1;
charx = 'a';
for (intn = sizeOfStack - 1; n != m - 2; n--) {
x = s.top();
s.pop();
if (sizeOfStack % 2 == 0&&n>m) { st1.push(x); }
elseif (sizeOfStack % 2 == 1&&n != m) { st1.push(x); }
}
cout<while (!st1.empty()) {
x = st1.top();
st1.pop();
s.push(x);
}
}
intmain()
{
srand(time(0));
stackst;
intn;
cin>>n;
for (inti = 0; ist.push(rand() % 10);
}
deleteMid_util(st, st.size());
while (!st.empty())
{
intp = st.top();
st.pop();
cout<}
return0;
}




Download 0.81 Mb.

Do'stlaringiz bilan baham:




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