How to sort a vector of repeated integers with C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    std::vector<int> arr = {4, 2, 2, 0, 8, 3, 3, 5, 2, 0, 1};

    std::sort(arr.begin(), arr.end()); 

    for (int num : arr) {
        std::cout << num << " ";
    }
    
    return 0;
}



/*
run:

0 0 1 2 2 2 3 3 4 5 8 

*/

 



answered Jul 5, 2025 by avibootz
...