+ 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

3rd Dec 2022, 8:14 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Respuestas
+ 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/
3rd Dec 2022, 10:54 AM
Tibor Santa
Tibor Santa - avatar
+ 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.
3rd Dec 2022, 2:13 PM
Bob_Li
Bob_Li - avatar