作业帮 > 综合 > 作业

数据结构实验 线性表的基本操作:括号配对检查.

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/21 09:44:15
数据结构实验 线性表的基本操作:括号配对检查.
输入一个只有左括号“(”和右括号“)”的序列,程序对括号配对的正确性检查并给出结果,配对检查的算法中用到栈结构 结构说明:栈结构用顺序存储方式实现,结构设定如下所示:
#define DATATYPE1 int
#define MAXSIZE 100
typedef struct
{DATATYPE1 data[MAXSIZE];
int top;
}SEQSTACK
用c语言编程
#include
using namespace std;
class Stack
{
public:
int size;
int top;
char *stack;
Stack(int m);
bool push(char item);//入栈
bool pop();//出栈
bool isempty();//是否为空
void clear();//清空栈
int Size();//栈中元素个数
Stack();
char Top();
};
#include
#include"Stack.h"
using namespace std;
Stack::Stack(int m){
top=-1;
stack=new char[m];
size = 0;
}
void Stack::clear(){
delete []stack;
size = 0;
stack=NULL;
}
Stack::Stack(){
clear();
}
bool Stack ::push(char item){
top++;
stack[top]=item;
size++;
return true;
}
bool Stack::isempty(){
if(stack == NULL)
return true;
else
return false;
}
bool Stack::pop(){
if(isempty()){
cout