火车进出站次序问题的一个程序,请指点!!

bary1980 2002-10-27 08:41:53
#include<stack>
#include<iostream>

using namespace std;
stack<int> input; //来的火车
stack<int> station; //进站的火车
stack<int> output; //出站的火车
static int i;
#define car_number 3

void dot(stack<int> _input,stack<int> _station,stack<int> _output)
{
stack<int> a_input=_input;
stack<int> a_station=_station;
stack<int> a_output=_output;
stack<int> to_buffer;
//输入的时候
if (!_input.empty())
{
_station.push(_input.top());
_input.pop();
dot(_input,_station,_output);
};
//输出的时候
if (!a_station.empty())
{
a_output.push(a_station.top());
a_station.pop();
//************输出一个堆栈的所有元素***********
if (a_output.size()==car_number) {
while(!a_output.empty())
{
to_buffer.push(a_output.top());
a_output.pop();
}
while(!to_buffer.empty())
{
cout<<to_buffer.top();
to_buffer.pop();
}
cout<<endl;
}
//*********************************************
dot(a_input,a_station,a_output);
}

};

void main()
{
for(int i=car_number; i>0 ; i--)
{
input.push(i);
}

dot(input,station,output);
}
请各位指点一下,
谁还有其他的方法拿出来大家一起讨论讨论!
...全文
102 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bary1980 2002-10-29
  • 打赏
  • 举报
回复
请指点
baryjim 2002-10-29
  • 打赏
  • 举报
回复
还算不错,感觉
baryjim 2002-10-28
  • 打赏
  • 举报
回复
这样的程序也敢拿出来!!!
baryjim 2002-10-28
  • 打赏
  • 举报
回复
不知道acm的情况怎样?具体名次如何?

33,010

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧