Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <bits/stdc++.h>
- #include<string>
- #define MAX 100
- #include"stack.h"
- using namespace std;
- class Paranthesis{
- Stack s;
- char str[MAX];
- public:
- void check(){
- cout<<"\nEnter # after expression(At the end)\n";
- cout<<"\nEnter Expression: ";
- cin.getline(str,MAX,'#');
- char ch;
- bool flag=0;
- for(int i=0;str[i]!='\0';i++)
- {
- if(str[i]=='(' || str[i]=='[' || str[i]=='{')
- s.push(str[i]);
- if(str[i]==')'||str[i]==']'||str[i]=='}')
- {
- if(s.isEmpty()){
- flag = 1; break;}
- ch=s.pop();
- if((str[i]==')'&& ch!='(') ||(str[i]==']'&& ch!='[')||(str[i]=='}'&& ch!='{'))
- {
- cout<<"\nNot parenthesized At "<<i<<" = "<<str[i];
- flag=1;
- break;
- }
- }
- }
- if(s.isEmpty()==1 && flag==0)
- cout<<"\nExpresseion is Well Parenthesized.";
- else
- cout<<"\nExpression is not Well Parenthesized.";
- }
- };
- int main(){
- Paranthesis p;
- p.check();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement