markdown guide
 

I have done like this:

bool validateBrackets(const std::string& data) {

  std::stack<char> brackets;  

  for (const auto& d : data) {
    if (d == '[' || d == '(' || d == '{') {
      brackets.push(d);
    }      
    else if (d == ']') {
     if (brackets.top() == '[')
       brackets.pop(); 
      else 
        return false;
    }
    else if (d == ')') {
     if (brackets.top() == '(')
       brackets.pop();
      else 
        return false;
    }
    else if(d == '}') {
     if (brackets.top() == '{')
       brackets.pop();
      else 
        return false;
    }
  }

  return true;
}

 

yasss 👏👏 I like the direct comparison for the bracket pairings. More efficient than a map 😬😁

Classic DEV Post from Jan 18

Sh*tpost: can we stop saying "syntactic sugar"?

What does it actually mean? you're not helping!

creator profile image
interactive experiences which augment perspective. iOS and AR Engineer

dev.to is where software developers stay in the loop and avoid career stagnation.

Sign up (for free)