#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
typedef char ElemType;
typedef struct node
{
ElemType data;
struct node *next;
}LStackNode,*LinkStack;
void InitStack(LinkStack *top);//将链栈初始化
int StackEmpty(LinkStack top);//判断链栈是否为空
int GetTop(LinkStack top,ElemType *e);//取栈顶元素
int PushStack(LinkStack top,ElemType e);//进栈操作
int PopStack(LinkStack top,ElemType *e);//出栈操作
int StackLength(LinkStack top);//求表长操作
void DestroyStack(LinkStack top);//销毁链表
int Match(ElemType e,ElemType ch);//判断括号
#include "括号配对.h"
void InitStack(LinkStack *top)//将链栈初始化
{
if((*top = (LinkStack)malloc(sizeof(LStackNode)))== NULL)
{
exit(-1);
}
(*top)->next = NULL;
}
int StackEmpty(LinkStack top)//判断链栈是否为空
{
if(top->next == NULL)
{
return 1;
利用栈的基本操作,检查括号是否匹配
最新推荐文章于 2022-10-09 19:05:23 发布
这段代码展示了如何使用链栈来检查输入的括号表达式是否匹配。通过定义链栈结构并实现进栈、出栈等操作,配合Match函数判断括号配对,实现了括号匹配的检查功能。
摘要由CSDN通过智能技术生成