2b #include <csldlib>#include <ioslręą'm># includc <siack>
using namespace std;
irit inain(int argc. char *argv[J)
J slack <inl> S,P: int a.min; char b; for (inl i = 0; i < 5; H-+)
; coul«"podaj liczbe"«endl; cin»a: S.push(a): > cout«endl:
//główna funkcja:
inl x = S.sizc().y = x: for (im i = 0: i < x: i++)
|
for (inl i« 0: j < y: j++)
if(j~.Q)| min = S.lop(): S.pop(); J clse {
if (min > S.lopO) { P.push(min); min = S.lop(): S.popO; } cłsc (P.push(.S.lopO); S.pop(); J
P.push(min): for (int j = 0 ;j <y:j++)
i
S.push(P.topO);
P.popO;
i i i
//wypisanie: coui«cndl«cndl: x = .S.si/c():
for (inl i =0; i < x: i++)
P
coui«.S.(op()«"
S.pop():
) cout«endl; systcnifPAUSE"): return EXIT_SUCCESS;
2c. //includc <cstdlib>#include <iostream>#include < siack -using namcspacc std; int main(int argc. char *argv[|)[ stack <int> S,P; int a,min,k;char b;
for (int i = 0; i < 5; i++)
i
|
cout«"podaj licz.bc"«cndl; cin»a;
S.push(a);
cout«endl;
int x = S.size(),y = x; int 11=0;
for (int j = 0; j < y; j++)
if(j=0){ min=S.top(); P.push(S.topO); S.popO'- ! elsc if(min>=.S.top())! min=S.top();
P.push(S.topO); S.popO; ll=j; } clse {
P.push(S.topO); S.popO; }
\
i
for (intj = 0;j<y;j-H-)
(
i
if(j=y-ll -1 ) P.pop(); else (
S.push(P.topO);
P.pop();}
coul«endł«endl; x = S.sia(); for (int i = 0; i < x; i++)
f
1
cout«S.top()«" | S.popO;
}
cout«cndi; syslcm("PAOSE''); retum r-XU _SOCCHSS;