4.3 replace ternary

master
NaiJi ✨ 3 years ago
parent a291f64c7d
commit 892c0539fa

@ -12,11 +12,12 @@ struct Node
template <typename T>
T max(const std::unique_ptr<Node<T>>& node, T max_value)
{
return (node)
? max(node->next, (node->value > max_value)
? node->value
: max_value)
: max_value;
if (!node)
return max_value;
return max(node->next, (node->value > max_value)
? node->value
: max_value);
}
int main()
@ -24,7 +25,7 @@ int main()
{
using NodeT = Node<std::string>;
auto head = std::make_unique<NodeT>(NodeT{"5", nullptr});
auto head = std::make_unique<NodeT>(NodeT{"JKFHDJKSFHaaaaaaaaaaJKSFHKJSDJFSDKH", nullptr});
head->next = std::make_unique<NodeT>(NodeT{"12", nullptr});
head->next->next = std::make_unique<NodeT>(NodeT{"35", nullptr});
head->next->next->next = std::make_unique<NodeT>(NodeT{"JKFHDJKSFHKJSDJFSDKH", nullptr});

Loading…
Cancel
Save