+ 1
Is minmax better than minmax_element
Refer code below: Minmax and minmax_element works same for non sorted data. Which is better than other ? https://code.sololearn.com/c7liJLBQD8XB/?ref=app
2 Answers
+ 4
I think neither is better than the other. They have the same time complexity. They just have different arguments and different return types.
https://www.geeksforgeeks.org/stdminmax-stdminmax_element-c-stl/
https://cplusplus.com/reference/algorithm/minmax_element/
https://cplusplus.com/reference/algorithm/minmax/
+ 2
minmax is convenient if you are using auto, which creates an iterator list, so you don't have to specify begin and end. But you cannot use it directly for vector or list. You can use minmax_element though.
try replacing 'auto' with 'vector<int>' in the two demo classes. The second will throw error messages.