建立顺序栈,实现火车的调度(软座区(s)全部在前,硬座区(h)全部在后)
/* Note:Your choice is C IDE */#include "stdio.h"
#include<string.h>
#define MAXSIZE 100
#define datatype char
typedef struct
{
datatype stack[MAXSIZE];
int top;
}seqstack;
seqstack *s;
int push(seqstack *s,datatype x)
{
if(s->top>=MAXSIZE-1)
{
printf("stack overflow!\n");
return(FALSE);
}
else{
s->stack[++s->top]=x;
return(TRUE);
}
}
int pop(seqstack *s,datatype *x)
{
if (s->top<0)
{
printf("stack empty!\n");
return(FALSE);
}
else{
*x=s->stack[s-top];
s->top--;
return (TRUE);
}
}
void main()
{
seqstack *s;
char x[MAXSIZE]; char ch2;
scanf("%s",x);
int j=0;
s-stack[0]='#';
s->top=0;
ch2=x[j];
while (!(ch2=='#')&&gettop(s)=='#')
{
if(ch2!='h')
{
printf("%c",ch2);
ch2=x[++j];
}
else
{
push(s,ch2);
ch2=x[++j];
}
}
pop(s,ch2);
printf("%s\n",s->seqstack[j++]);
}这是一个初步的程序,还请高手帮忙改正!!!多谢,多谢!!!