stack问题 E2 (b)

#include<iostream>
using namespace std;
const int maxstack=5;
enum bb{success,overflow,underflow};
typedef int aa;
class Stack
{
public:
 Stack()
 {
  count=0;
 }
 bool empty()const
 {
  bool cc=true;
  if(count>0)
   cc=false;
  return cc;
 }
 bb pop()
 {
  bb cc=success;
  if(count==0)
   cc=underflow;
  else--count;
  return cc;
 }
 bb top(aa &i)const
 {
  bb cc=success;
  if(count==0)
   cc=underflow;
  else
   i=entry[count-1];
  return cc;
 }
 bb push(const aa &i)
 {
  bb cc=success;
  if(count>=maxstack)
   cc=overflow;
  else
   entry[count++]=i;
  return cc;
 }
private:
 int count;
 aa entry[maxstack];
};
int main()
{
 Stack source;
 Stack temporary;
 Stack dest;
 int n,i,j;
 cin>>n;
 for(j=0;j<n;j++)
 {
  cin>>i;
  source.push(i);
 }
 while(!source.empty())
 {
  temporary.push(i);
  source.top(i);
  source.pop();
 }
 while(!temporary.empty())
 {
  cout<<i;
  source.push(i);
  dest.push(i);
  temporary.top(i);
  temporary.pop();
 }
 return 0;
}

 

 

 

  

 


 

posted @ 2013-08-28 17:15  没有颜色  阅读(135)  评论(0)    收藏  举报