火车进出站问题:有多少种出站序列
来源:互联网 发布:考研作息时间表知乎 编辑:程序博客网 时间:2024/06/11 21:03
#include <stdio.h>
#include <malloc.h>
#include <iostream>
using namespace std;
#define STACK_SIZE 20
typedef struct
{
int stack[STACK_SIZE];
int top;
}SqStack;
int count=1;
bool InitStack(SqStack &S)
{
S.top=-1;
return true;
}
bool StackEmpty(SqStack S)
{
if (S.top==-1)
{
return true;
}
else
return false;
}
bool ClearStack(SqStack &S)
{
S.top=-1;
return true;
}
int StackLength(SqStack S)
{
return S.top+1;
}
bool GetTop(SqStack &S,int &e)
{
if (S.top==-1)
{
return false;
}
e=S.stack[S.top];
return true;
}
bool Push(SqStack &S,int e)
{
if (S.top>=STACK_SIZE-1)
{
return false;
}
S.top++;
S.stack[S.top]=e;
return true;
}
int Pop(SqStack &S)
{
int e;
if (S.top==-1)
{
return -1;
}
e=S.stack[S.top];
S.top--;
return e;
}
void InOutStack(SqStack &input,SqStack &S,SqStack &output)
{
if (StackEmpty(S)&&StackEmpty(input))
{
int i;
printf("%4d | ",count++);
for (i=0;i<=output.top;i++)
{
printf("%d ",output.stack[i]);
}
printf("\n");
}
else
{
if (!StackEmpty(input))
{
Push(S,Pop(input));
InOutStack(input,S,output);
Push(input,Pop(S));
}
if(!StackEmpty(S))
{
Push(output,Pop(S));
InOutStack(input,S,output);
Push(S,Pop(output));
}
}
}
int main()
{
SqStack S,input,output;
InitStack(S);
InitStack(input);
InitStack(output);
int n=1;
printf("请输入列车数:");
scanf("%d",&n);
int i;
for(i=n;i>0;i--)
{
Push(input,i);
}
printf("情况序号 出站次序情况\n");
InOutStack(input,S,output);
return 0;
}
- 火车进出站问题:有多少种出站序列
- 火车进出站序列问题简述
- 火车出站入站问题
- 火车进出站问题---栈
- 火车进站出站问题
- 火车进站出站问题
- HDU 1022 火车进出站问题
- HDU1022--火车进出站问题Ⅰ
- HDU 1022 火车进出站问题
- HDU-1022-火车进出站问题 .
- hdoj 1022 火车进出站问题
- HDU 1022 火车进出站问题
- HDU-1022 火车进出站问题【栈】
- 火车进出铁轨问题
- 火车出站
- 火车出站
- 栈的思想解决火车出站问题
- 【火车进出站 - 递归全排列 + 遍历】
- [Android JNI]Android的NDK开发-基于NDK的OpenGL开发
- IOS开发学习基础--------C语言(二)
- php中static静态变量的使用方法详解
- mvc中cshtml与aspx页面的不同
- 安卓微信数据库解密
- 火车进出站问题:有多少种出站序列
- Python 学习入门(9)—— set操作
- dstat使用
- SMTP server rejected auth: 535 Error: authentication failed Gerrit 认证邮箱报错
- HTML中的标签textarea的属性及用法
- 编程语言
- Activity打成jar包(资源文件的问题)
- 成为一名PHP专家其实并不难
- POJ_题目分类