TopicWise/StacksAndQueues/ParenthesisChecker.cpp
// Function to return if the paranthesis are balanced or not
Function to return if the paranthesis are balanced or not
Function to return if the paranthesis are balanced or not
bool ispar(string x)
{
    stack<char> s;
    for(int i = 0; i < x.length(); i++)
    {
        char ch = x[i];
        if(ch == '(' || ch == '[' || ch == '{')
        s.push(ch);
        else if(ch == ')' || ch ==']' || ch =='}')
        {
            if(s.empty())
            {
                return false;
            }
            else if(ch == ')' && s.top() != '(')
            {
                return false;
            }
            else if(ch == '}' && s.top() != '{')
            {
                return false;
            }
            else if(ch == ']' && s.top() != '[')
            {
                return false;
            }
            else
            {
                s.pop();
            }
        }
    }
    if(s.empty())
    return true;
    else
    return false;
}
bool ispar ( string x ) { stack < char > s ; for ( int i = 0 ; i < x . length ( ) ; i ++ ) { char ch = x [ i ] ; if ( ch == ' ' || ch == ' ' || ch == ' ' ) s . push ( ch ) ; else if ( ch == ' ' || ch == ' ' || ch == ' ' ) { if ( s . empty ( ) ) { return false ; } else if ( ch == ' ' && s . top ( ) != ' ' ) { return false ; } else if ( ch == ' ' && s . top ( ) != ' ' ) { return false ; } else if ( ch == ' ' && s . top ( ) != ' ' ) { return false ; } else { s . pop ( ) ; } } } if ( s . empty ( ) ) return true ; else return false ; }
Function to return if the paranthesis are balanced or not
Function to return if the paranthesis are balanced or not