SHAHARIAR_ISLAM_SAKIB's blog

By SHAHARIAR_ISLAM_SAKIB, history, 3 months ago, In English

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

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 months ago, # |
  Vote: I like it +1 Vote: I do not like it

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

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

seek help

»
2 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

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