Search:
Forum
General C++ Programming
sum of stack
sum of stack
Apr 22, 2013 at 2:10am UTC
nailamunir
(10)
plz check why does it not provide the require output
#include<iostream>
using namespace std;
struct Stack
{
int item[50],top;
};
void push(Stack *a,int no)
{
if(a->top==50)
{
cout<<"stack overflow"<<endl;
exit(1);
}
else
a->item[++a->top]=no;
}
int pop(Stack *b)
{
if(b->top==-1)
{
cout<<"underflow"<<endl;
exit(1);
}
else
return b->item[b->top--];
}
void sum(Stack *c,int n)
{
c ->item[c->top--]=n;
}
int main()
{
Stack s1,s2,s;
s1.top=-1;
s2.top=-1;
int no,limit,i;
cout<<"enter length of first stack"<<endl;
cin>>no;
for(i=0;i<limit;i++)
{
cin>>no;
push(&s1,no);
}
cout<<"enter length of seconf stack"<<endl;
cin>>no;
for(i=0;i<limit;i++)
{
cin>>no;
push(&s2,no);
}
if(s1.top==s2.top)
{
s.top=s1.top;
int summ=pop(&s1)+pop(&s2);
sum(&s,summ);
}
cout<<pop(&s)<<endl;
return 0;
}
Apr 22, 2013 at 2:18am UTC
Anmol444
(638)
Use code tags.
The <> under format
Topic archived. No new replies allowed.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs