• + 0 comments

    Yes it is. If !s.empty() is placed first and the stack is empty, s.peek()=='[' will not be executed, hence no runtime error.This is due to the short circuit evaluation nature of if statements. However the order you gave above gives runtime error because s.peek()=='[' is executed first and this may cause errors if the stack is empty.