Given a string containing just the characters '(', ')', '{', '}', '['  and ']', determine if the input string is valid.The brackets must close in the correct order, () and ()[]{} are  all valid but (] and ([)] are not.The following is my code, which has already been tested on a onlinejudge. Can someone help me give some comments for the code itself?bool isValid(string s) {    stack<char> s1;    string::iterator it = s.begin();    map<char, char> x;    x['('] = ')';    x['['] = ']';    x['{'] = '}';    for (; it!=s.end(); ++it) {        if (!s1.empty()) {            char c = s1.top();            if(x[c] == *it) {                s1.pop();            }            else {                s1.push(*it);            }        }        else {            s1.push(*it);        }    }       return s1.empty();}
Valid Parentheses
c++;interview questions;stack