#include<stdio.h>
#include<stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCRAMENT 10
#define INFEASIBLE -1
#define OK 1
#define OVERFLOW -2
#define ERROR 0
#define FALSE 0
#define TRUE 1
typedef int Status;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define SElemType char
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &S){
S.base = (SElemType*)malloc(STACK_INIT_SIZE*sizeof(SElemType));
if (!S.base) exit(OVERFLOW);
S.top = S.base;
S.stacksize = STACK_INIT_SIZE;
return OK;
}
Status GetTop(SqStack &S, SElemType &e){
if (S.top == S.base) return ERROR;
e = *(S.top - 1);
return OK;
}
Status Push(SqStack &S, SElemType e){
if (S.top - S.base >= S.stacksize){
S.base = (SElemType*)realloc(S.base, (S.stacksize + STACKINCREMENT)*sizeof(SElemType));
if (!S.base)exit(OVERFLOW);
S.top = S.base;
S.stacksize += STACKINCREMENT;
}
*S.top++ = e;
return OK;
}
Status Pop(SqStack &S, SElemType &e){
if (S.top == S.base) return ERROR;
e = *S.top--;
return OK;
}
Status StackEmpty(SqStack &S){
if (S.top == S.base)
return TRUE;
else
return FALSE;
}
int main(){
SqStack S, H;
char e;
int i, n;
char t[80];
InitStack(S);
InitStack(H);
printf("请输入车厢长度:");
scanf_s("%d", &n);
if (n > 80) exit(OVERFLOW);
printf("请输入硬席(H)和软席车厢(S)序列:");
for (i = 0;i < n; ++i){
scanf_s("%c", &t[i]);
}
for (i = 0; i < n; i++){
if (t[i] == 'H')
Push(H,t[i]);
else
Push(S,t[i]);
}
while (!StackEmpty(S)){
Pop(S, e);
printf("%c", e);
}
while (!StackEmpty(H)){
Pop(H, e);
printf("%c", e);
}
return 0;
}
报错信息发出来看看?