Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to create a sorted copy of part of a vector in C++

1 Answer

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

int main()
{
    std::vector<int> vec = { 4, 9, 19, 16, 24, 21, 10, 3 }, v(5);

    partial_sort_copy(vec.begin(), vec.end(), v.begin(), v.end());

    for (auto const &n: v) {
        std::cout << n << " ";
    }
}




/*
run:

3 4 9 10 16 

*/

 



answered Jun 9, 2023 by avibootz

Related questions

1 answer 172 views
1 answer 179 views
1 answer 78 views
2 answers 122 views
1 answer 109 views
1 answer 117 views
117 views asked May 12, 2021 by avibootz
...