#include<iostream>
using namespace std;
class stack
{public:
int top,s,a[10];
void push(int d);
int pop();
stack(){
top=-1,s=4;
}
};
void stack::push(int d)
{if(top>=s-1)
cout<<"stack is full\n";
else
a[++top]=d;
}
int stack::pop()
{int c;
if(top<=-1)
{
cout<<"stack is empty\n";
return 0;
}
else
{ c =a[top--];
return c;
}}
int main()
{stack s,s1; int i,j,n,a,b;
cout<<"enter ";
for(i=0;i<4;i++) //enter 4 numbers
{cin>>n;
s.push(n);
}
for(i=3;i>0;i--)
{
for(j=i;j>0;j--)
{a=s.pop(); // pop 2 numbers in stack
b=s.pop();
if(a>=b)
{s1.push(a); //store minimum into 2nd stack s1
s.push(b);
}
else
{s1.push(b);
s.push(a);
}
}
while(s1.top>-1)
{n=s1.pop();
s.push(n);
}
}
while(s.top>-1)
cout<<s.pop();
return 0;
}
using namespace std;
class stack
{public:
int top,s,a[10];
void push(int d);
int pop();
stack(){
top=-1,s=4;
}
};
void stack::push(int d)
{if(top>=s-1)
cout<<"stack is full\n";
else
a[++top]=d;
}
int stack::pop()
{int c;
if(top<=-1)
{
cout<<"stack is empty\n";
return 0;
}
else
{ c =a[top--];
return c;
}}
int main()
{stack s,s1; int i,j,n,a,b;
cout<<"enter ";
for(i=0;i<4;i++) //enter 4 numbers
{cin>>n;
s.push(n);
}
for(i=3;i>0;i--)
{
for(j=i;j>0;j--)
{a=s.pop(); // pop 2 numbers in stack
b=s.pop();
if(a>=b)
{s1.push(a); //store minimum into 2nd stack s1
s.push(b);
}
else
{s1.push(b);
s.push(a);
}
}
while(s1.top>-1)
{n=s1.pop();
s.push(n);
}
}
while(s.top>-1)
cout<<s.pop();
return 0;
}
No comments:
Post a Comment