stack.h

来自「数据结构的栈的应用」· C头文件 代码 · 共 75 行

H
75
字号
typedef struct Node1
{
   char ch;
   struct Node1 *Next;
}Optr,*LinkOptr;//运算符栈

typedef struct Node
{
    int num;
	struct Node *Next;
}Opnd,*LinkOpnd;//运算数栈

void InitStack(LinkOptr *S)
{
	(*S)=(LinkOptr)malloc(sizeof(Optr));   
    (*S)->Next=NULL;
}//初始化运算符栈

void InitStack(LinkOpnd *S)
{
    (*S)=(LinkOpnd)malloc(sizeof(Opnd));
    (*S)->Next=NULL;
}//初始化运算数栈

int PushOptr(LinkOptr pr,char ch1)
{
   LinkOptr temp;
   temp=(LinkOptr)malloc(sizeof(Optr));
   temp->ch=ch1;
   temp->Next=pr->Next;
   pr->Next=temp;
   return true;
}//插入运算符到运算符栈

int PushOpnd(LinkOpnd pn,int num1)
{
   LinkOpnd temp;
   temp=(LinkOpnd)malloc(sizeof(Opnd));
   temp->num=num1;
   temp->Next=pn->Next;
   pn->Next=temp;
   return true;
}//插入运算数到运算数栈

char PopOptr(LinkOptr S)
{
   if(S->Next==NULL)
	   return true;
   LinkOptr temp;
   temp=S->Next;
   S->Next=temp->Next;
   return temp->ch;
   
}//删除运算符栈的栈顶元素

int PopOpnd(LinkOpnd S)
{
   if(S->Next==NULL)
	   return true;
   LinkOpnd temp;
   temp=S->Next;
   S->Next=temp->Next;
   return temp->num;

}//删除运算数栈的栈顶元素

char GetTop1(LinkOptr S)
{
   return S->Next->ch;
}//返回运算符栈的栈顶元素

int GetTop2(LinkOpnd S)
{
   return S->Next->num;
}//返回运算数栈的栈顶元素

⌨️ 快捷键说明

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