一个算法设计题 急啊?

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:08:47
以整数序列a,b,c,d作为栈s的输入,利用push,pop操作,写出所有可能的输出,并编程实现算法.

/*
程序使用递归模拟栈操作
每次栈非空时且输入未空时都可以选择两个操作
进栈或者出栈
每次栈非空时但输入已空时都可以
进行出栈
每次栈已空时但输入非空时都可以
进行入栈
每次栈已空时且输入已空时都可以
将输出序列打印
*/

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>

char input[5] = {'a', 'b', 'c', 'd'};
char output[5] = {'\0', '\0', '\0', '\0', '\0'};

typedef struct stack
{
int count;
char mystack[5];
}MYSTACK;

int mypush(int in, MYSTACK *psta)
{
psta->mystack[psta->count++] = input[in];
return 1;
}

int mypop(int out, MYSTACK *psta)
{

output[out] = psta->mystack[--psta->count];
return 1;
}

void myprint()
{
for(int i = 0; i < 4; i++)
{
printf("%c ", output[i]);