|
| |||||||||
| Tags: algorithm, cpp, functions, header files, library, partial_sort_copy |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| The partial_sort_copy() function in C++
Hi, I am the student of the BSC-IT. I can have the practical knowledge of the C++ language programming. Because, I can recently created the project on the Payroll Management in the C++ language programming. Even though I can not know anything about the partial_sort_copy() function in the C++ language programming. So, I want to know about the partial_sort_copy() function of the C++ language. I can also want to know about how can I use the partial_sort_copy() function in the C++ programming language. Therefore, Anyone can be there who can have the solution for me on the partial_sort_copy() function in the C++ language. |
|
#2
| ||||
| ||||
| The partial_sort_copy()
The partial_sort_copy() function can copies the smallest elements that can be present in the given specified range [fst,lst) to [rslt_fst,rslt_lst), sorting an elements that can be copied. The amount of an elements that can be copied is (rslt_lst-rslt_fst). The range [fst,lst) can remains unmodified. The elements can be compared using an operator "<" for the first version and comp for the second. |
|
#3
| |||
| |||
| partial_sort_copy()
The partial_sort_copy() function can be used in the C++ language to copy the range and to sort this range partially. The following can be the general form of the partial_sort_copy() function in the C+= language as : Code: template <class InptItrtr, class RndmAcsItrtr>
RndmAcsItrtr
partial_sort_copy ( InptItrtr fst,InptItrtr lst,
RndmAcsItrtr rslt_first,
RndmAcsItrtr rslt_lst ); |
|
#4
| ||||
| ||||
| The partial_sort_copy() function in C++
The following program can explains you about how the partial_sort_copy() function can be used or implemented in the C++ language as : Code: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool mfunction (int a,int b)
{
return (a<b);
}
int main ()
{
int mints[] = {9,8,7,6,5,4,3,2,1};
vector<int> mvector (5);
vector<int>::iterator t;
partial_sort_copy (mints, mints+9, mvector.begin(), mvector.end());
partial_sort_copy (mints, mints+9, mvector.begin(), mvector.end(), mfunction);
cout << "mvector contains:";
for (t=mvector.begin(); t!=mvector.end(); ++t)
cout << " " << *t;
cout << endl;
return 0;
} Code: mvector contains: 1 2 3 4 5 |
|
#5
| ||||
| ||||
| Re: The partial_sort_copy() function in C++
The following can be the parameters of the partial_sort_copy() function in the C++ programming language : 1. rslt_fst, rslt_lst : These parameters can be used in the partial_sort_copy() function of the C++ language for the Random-Access iterators to the final and starting positions of the destination sequence. The range used can be [rslt_fst,rslt_lst). 2. comp : This parameter can be used in the partial_sort_copy() function of the C++ language can contains the comparison function object that can taking two values of the similar type than those can contained in the given range and can returns the true value if the first argument can goes before the second argument in the particular strict weak ordering that it defines and false value otherwise. 3. fst, lst : These parameters can be used in the partial_sort_copy() function of the C++ language for the input iterators to the final and starting positions of the given specified sequence to copy from. The range used can be [fst,lst). |
|
#6
| ||||
| ||||
| The partial_sort_copy() function in C++
I can suggest you to go through the following code of lines that can help's you to understand the partial_sort_copy() function of the C++ language more easily and quickly : Code: #include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
int main()
{
typedef std::vector<int, std::allocator<int> > Vector;
typedef std::ostream_iterator<int, char,
std::char_traits<char> > Iter;
const Vector::value_type b[] = {
17, 3, 5, -4, 1, 12, -10, -1, 14, 7,
-6, 8, 15, -11, 2, -2, 18, 4, -3, 0
};
Vector w1 (b + 0, b + sizeof b / sizeof *b);
std::cout << "For the vector: ";
std::copy (w1.begin (), w1.end (), Iter (std::cout, " "));
std::partial_sort (w1.begin (), w1.begin () + 7,
w1.end ());
std::cout << "\n\nA partial_sort of seven elements "
<< "gives: \n ";
std::copy (w1.begin (), w1.end (), Iter (std::cout, " "));
std::cout << std::endl;
Vector w2 (Vector::size_type (10), 0);
std::partial_sort_copy (w1.begin () + 10, w1.end (),
w2.begin (), w2.end ());
std::cout
<< "\nA partial_sort_copy of the last ten elements "
<< "gives: \n ";
std::copy (w2.begin (), w2.end (), Iter (std::cout, " "));
std::cout << std::endl;
return 0;
} Code: For the vector: 17 3 5 -4 1 12 -10 -1 14 7 -6 8 15 -11 2 -2
18 4 -3 0
A partial_sort of seven elements gives:
-11 -10 -6 -4 -3 -2 -1 17 14 12 7 8 15 5 3 2 18 4 1 0
A partial_sort_copy of the last ten elements gives:
0 1 2 3 4 5 7 8 15 18 |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "The partial_sort_copy() function in C++" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| c++ equivalent function to the c-function 'sprintf | Dilbert | Software Development | 6 | 13-12-2011 04:03 PM |
| c# function equivalent to gettime function in javascript | Omaar | Software Development | 4 | 10-03-2010 10:44 PM |
| How to pass function with parameters to another function in PHP? | Linoo | Software Development | 5 | 27-02-2010 07:52 PM |
| How does abstract function differs from virtual function? | Maddox G | Software Development | 5 | 29-01-2010 11:32 AM |
| Function keys don't function under windows XP | GunFighter | Hardware Peripherals | 3 | 09-04-2009 12:07 AM |