stack.c

来自「基本的计算器程序」· C语言 代码 · 共 55 行

C
55
字号
#include "stack.h"

/**********************以下为各个子函数*************************/
void InitStackChar(StackChar  **s)
{   
        *s = (StackChar*)malloc(sizeof(StackChar));   //malloc()返回指向被分配内存的指针,否则返回空指针NULL        
        (*s)->Top = -1;   
}  
          
void InitStackDouble(StackDouble  **s)
{   
        *s = (StackDouble*)malloc(sizeof(StackDouble));
        (*s)->Top = -1;   
}  

void PushChar(StackChar *s,char x)
{   
        s->Top++;
        s->Stack[s->Top]=x;
}   
   
   
char PopChar(StackChar *s)
{   
        char x;   
        x=s->Stack[s->Top];
        s->Top--;   
        return(x);            
}   
   
char GetTopChar(StackChar *s)
{               
        return(s->Stack[s->Top]);
}   
 
double PopDouble(StackDouble *s)
{   
        double x;   
        x=s->Stack[s->Top];
        s->Top--;   
        return(x);  
}   
 
void PushDouble(StackDouble *s,double x)
{   
        s->Top++;
        s->Stack[s->Top]=x;          
}   

double getTopdouble(StackDouble *s)
{               
        return(s->Stack[s->Top]);
}   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?