#include<bits/stdc++.h>
using namespace std;
#define Elemtype int
#define STACKINCREMENT 10
typedef struct{
Elemtype *base;
Elemtype *top;
int stacksize;
}SqStack;
void init(SqStack &s){
s.base= new Elemtype;
s.top=s.base;
s.stacksize=100;
}
void push(SqStack &s,char ch){
if(s.top-s.base>=s.stacksize){
s.base=new Elemtype;
s.top=s.base+s.stacksize;
s.stacksize+=STACKINCREMENT;
}
*s.top++=ch;
}
void show(SqStack s){
for(int i=0;i<s.stacksize;i++){
}
}
void bracketspd(SqStack &s){
string input;cout<<"请输入想要判断的字符串"<<endl;cin>>input;
for(int i=0;i<sizeof(input);i++){
if(input[i]=='{'||input[i]=='}'||input[i]=='['||input[i]==']'||input[i]=='('||input[i]==')')push(s,input[i]);
}
cout<<"显示字符串:"<<endl;
show(s);
}
int main(){
SqStack s;
init(s);
int flag;
cout<<"1.括号匹配检验\n2.表达式求值\n3.递归的应用(汉诺塔)"<<endl;
cin>>flag;
switch(flag){
case 1:
cout<<"括号匹配检验"<<endl;
bracketspd(s);
break;
case 2:
cout<<"表达式求值"<<endl;
break;
case 3:
cout<<"递归的应用"<<endl;
break;
default:
cout<<"没有该选项!"<<endl;
break;
}
return 0;
}
c++栈的应用:括号匹配,表达式求值,汉诺塔
于 2023-09-13 15:02:15 首次发布