只要操作数和操作符的具体节点的列举谢谢!
typedef struct{
float *base;
float *top;
int stacksize; }SqStack_f;
typedef struct{
char *base;
char *top;
int stacksize; }SqStack_c;
void InitStack_f(SqStack_f *s)
{
s->base=(float *)malloc(TTACK_INIT_SIZE*sizeof(float));
if(!s->base)
exit(1);
s->top=s->base;
s->stacksize=TTACK_INIT_SIZE;
}
void InitStack_c(SqStack_c *s)
{
s->base=(char *)malloc(TTACK_INIT_SIZE*sizeof(char));
if(!s->base)
exit(1);
s->top=s->base;
s->stacksize=TTACK_INIT_SIZE;
}
void GetTop_f(SqStack_f *s,float *e)
{
if(s->top==s->base)
{
printf("ERROR!\n");
exit(1);
}
*e=*(s->top-1);
}
void GetTop_c(SqStack_c *s,char *e)
{
if(s->top==s->base)
{
printf("ERROR!\n");
exit(1);
}
*e=*(s->top-1);
}
void Push_f(SqStack_f *s,float e)
{
if(s->top-s->base>=s->stacksize)
{
s->base=(float *)realloc(s->base,(s->stacksize+STACKINCREMENT)*sizeof(float));
if(!s->base)
{
printf("OVERFLOW!\n");
exit(1);
}
s->top=s->base+s->stacksize;
s->stacksize+=STACKINCREMENT;
}
*s->top++=e;
}
void Push_c(SqStack_c *s,char e)
{
if(s->top-s->base>=s->stacksize)
{
s->base=(char *)realloc(s->base,(s->stacksize+STACKINCREMENT)*sizeof(char));
if(!s->base)
{
printf("OVERFLOW!\n");
exit(1);
}
s->top=s->base+s->stacksize;
s->stacksize+=STACKINCREMENT;
}
*s->top++=e;
}
Devil10
相关分类