O'ZBEKISTON RESPUBLIKASI TOSHKENT AXBOROT TEXNALOGİYALARİ UNİVERSİTETİ
Amaliy mashg’ulot-4
BAJARDI:Rahimboyev Yusuf
TEKSHIRDI: Rustamova Mohichehra
1-topshiriq
#include
using namespace std;
stack st;
string ns;
char pastki_qismiga_joylashtir(char x)
{
if(st.size() == 0)
st.push(x);
else
{
char a = st.top();
st.pop();
pastki_qismiga_joylashtir(x);
st.push(a);
}
}
char teskari()
{
if(st.size()>0)
{
char x = st.top();
st.pop();
teskari();
pastki_qismiga_joylashtir(x);
}
}
int main()
{ st.push('1');
st.push('2');
st.push('3');
st.push('4');
cout<<"Asosiy Stack"<
cout<<"1"<<" "<<"2"<<" "
<<"3"<<" "<<"4"
<
teskari();
cout<<"teskari Stack"
<
while(!st.empty())
{
char p=st.top();
st.pop();
ns+=p; }
cout<
<
return 0;
}
2-topshiriq
#include
#include
using namespace std;
int main()
{
priority_queue sons,tuplam;
int n;
cout<<"N=";cin>>n;
for(int i=0;i
int son; cin>>son;
sons.push(son);
}
int urts=(sons.size())-(sons.size()/2);
int ulcham=sons.size();
for(int i=1;(i<=ulcham) && !sons.empty() ; i++)
if (urts==i && ulcham%2!=0) {
sons.pop();
} else if( (urts==i || (urts+1)==i ) && ulcham%2==0)
sons.pop();
else {
tuplam.push(sons.top());
sons.pop();
}
cout<<"Tuplam sonlar: ";
while (!tuplam.empty())
{
cout<
tuplam.pop();
}
return 0;
}
Do'stlaringiz bilan baham: |