I am working in C++. I have two statements involving the ternary operator.
std::stack<Node*> s; int depth = 0; /*modify depth integer and stack size, based on height of BST*/ depth = s.size() > depth ? s.size() : depth; std::stack<Node*> s; int depth = 0; /*modify depth integer and stack size, based on height of BST*/ s.size() > depth ? depth = s.size() : depth = depth; My question is this: Is there a standard way to assign a variable with the ternary operator? Is one of these forms more efficient, concise, or better than the other?
The second example seems to be more redundant than the first.
Edit: added comment that both s and depth are modified before the ternary operator.
int depth = s.size();would be enough here.depth = std::max<int>(depth, s.size())std::size_tto have the same type as s.size().