4.3 replace ternary

This commit is contained in:
NaiJi ✨ 2021-09-07 17:38:14 +03:00
parent a291f64c7d
commit 892c0539fa
1 changed files with 7 additions and 6 deletions

View File

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