栈二--括号匹配
2024年1月29日小于 1 分钟约 117 字
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include "stack.h"
const int maxLength=100;
void PrintMatchedPairs(char* expression){
Stack<int> s(maxLength);
int j;
length=strlen(expression);
for(int i=0;i<length;i++){
if(expression[i-1]=='(')s.push(i);
else if(expression[i-1]==')'){
if(!s.Pop(i)){
cout<<j<<"和"<<i<<"匹配"<<endl;
}
<!-- more -->
else cout<<"没有和第"<<i<<"个括号匹配的右括号"<<endl;
}
}
}