为生存而奔跑

   :: 首页 :: 联系 :: 聚合  :: 管理
  271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

留言簿(5)

我参与的团队

搜索

  •  

积分与排名

  • 积分 - 319563
  • 排名 - 75

最新评论

阅读排行榜

评论排行榜

#include<iostream>
#include
<stack>
using namespace std;
stack
<int>stackA,stackB;
void enqueue(int x)
{
 stackA.push(x);
}

int dequeue()
{
 
if(stackB.empty())
 
{
  
while(!stackA.empty())
  
{
   stackB.push(stackA.top());
   stackA.pop();
  }

 }

 
if(stackB.empty())
  
return -1;
 
int val=stackB.top();
 stackB.pop();
 
return val;
}

int main()
{
 
char ch;
 
int i=0;
 
while(cin>>ch)
 
{
  
if(ch=='e')
  
{
   enqueue(i
++);
  }

  
else cout<<dequeue()<<endl;
 }

}
posted on 2009-08-06 10:04 baby-fly 阅读(264) 评论(0)  编辑 收藏 引用 所属分类: Algorithm

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理