4-AMALIYOT ISHI
MAVZU:STACK,QUEUE,DEQUEUE(STEK,NAVBAT,DEK)
VARIANT-22
N ta elementdan tashkil topgan stack berilgan.stackni eng kichik elementini toping va uni 0 bilan almashtiring.
DASTUR KODI
#include
#include
using namespace std;
int main(){
stack st;
stack ans;
int n, a;
cin >> n;
cin >> a;
int mi = a;
st.push(a);
for (int i = 1; i < n; i++)
{
cin >> a;
if(mi > a)
mi = a;
st.push(a);
}
while (!st.empty())
{
a = st.top();
if (a == mi)
ans.push(0);
else
ans.push(a);
st.pop();
}
while (!ans.empty())
{
cout << ans.top() << " ";
ans.pop();
}
}
NATIJA:
Do'stlaringiz bilan baham: |