Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя SHAHARIAR_ISLAM_SAKIB

Автор SHAHARIAR_ISLAM_SAKIB, история, 5 месяцев назад, По-английски

sort(v.begin(),v.end(),greater ()); OR sort(v.rbegin(),v.rend()); OR sort(v.begin(),v.end()); reverse(v.begin(),v.end()); All these are the same

  • Проголосовать: нравится
  • -12
  • Проголосовать: не нравится

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by SHAHARIAR_ISLAM_SAKIB (previous revision, new revision, compare).

»
5 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

ok but i perfer sort(v.rbegin(), v.rend());

»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by SHAHARIAR_ISLAM_SAKIB (previous revision, new revision, compare).

»
2 месяца назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

seek help

»
2 месяца назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

They all have a time complexity O(n log n), in the sorting process the first one uses the greater<int>() comparator to sort in descending order based on this criterion while the second one uses reverse iterators instead of the comparator. But the third one actually adds a small constant factor because of the reversing, making the time complexity combined of O(n log n) + O(n) which is still O(n log n) overall but makes the first and the second methods slightly more efficient than it