下面代码设定“操作数”、"操作符”的栈的抽象数据类型的设计的具体节点?

只要操作数和操作符的具体节点的列举谢谢!

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
浏览 941回答 2
2回答

Devil10

这上面两个提问和回答是一起的,求大神指点!
打开App,查看更多内容
随时随地看视频慕课网APP