Saturday, February 7, 2015

Stack of stack in C++

#include<iostream>
using namespace std;
class stack
{public:
  int top,t,arr[50];
  void push(int c);
  int pop();
};
void stack::push(int c)
{arr[++top]=c;
}
int stack::pop()
{t=arr[top--];
}
int main()
{stack s;int n,no,i,j,z,ctr=-1;
 s.top=-1;
 cout<<"no:";
 cin>>n;
 cout<<"-1\n";
 for(i=0;i<n;i++)
 {do
  {cin>>no;
   if(no!=-1)
   s.push(no);
   ++ctr;
  }
  while(no!=-1);
  s.push(ctr);
  ctr=-1;
 }
 for(i=n-1;i>=0;i--)
 {cout<<i+1<<" Stack\n";
    s.pop();
    z=s.t;
    for(j=0;j<z;j++)
    {s.pop();
    cout<<s.t<<endl;
    }
 }
}

No comments:

Post a Comment

Contributors

Translate