|
| |||||||||
| Tags: algorithm, cpp, functions, header files, library, partial_sort |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Use of the partial_sort() in CPP
Hello, I am the student of the MSC-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. Eventhough I can not know anything about the partial_sort() function in the C++ language programming. So, I want to know about the partial_sort() function of the C++ language. I can also want to know about how can I use the partial_sort() function in the C++ programming language. Therefore, Anyone can be there who can have the solution for me on the partial_sort() function in the C++ language. |
|
#2
| ||||
| ||||
| The partial_sort() in CPP
Hello, The partial_sort() function can be used in the C++ language to Partially Sort an elements that can be in the given specified range. The following can be the general syntax of the partial_sort(0 function in the C++ language as : Code: template <class RndmAcesItrtr>
void partial_sort ( RndmAcesItrtr fst, RndmAcesItrtr mdl,
RndmAcesItrtr lst ); |
|
#3
| |||
| |||
| partial_sort() in CPP
The following can be the parameters of the partial_sort() function in the C++ programming language : 1. comp : This parameter can be used in the partial_sort() function of the C++ language for an object of the Comparison function that can taking two values of the same type than those can be contained in the given specified range. 2. fst, lst : These parameters can be used in the partial_sort() function of the C++ language for Random-Access iterators to the final and starting positions of the sequence that can be partial_sorted. The range used can be [fst,lst). |
|
#4
| ||||
| ||||
| The partial_sort()
The following program could illustrates you about that how you could use the partial_sort() function in the C++ language programming while using the partial_sort() function in the programming as shown below : Code: #include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
int main()
{
int d[1000];
int k;
for (l = 0; l < 1000; ++l)
d[l] = 1000 - l - 1;
partial_sort(&d[0], &d[1000]);
for (l = 0; l < 1000; ++l)
assert (d[l] == l);
return 0;
} |
|
#5
| ||||
| ||||
| Re: Use of the partial_sort() in CPP Program : Code: #include <iostream>
#include <algorchm>
#include <vector>
using namespace std;
bool mfnctn (int c,int d)
{
return (c<d);
}
struct myclass
{
bool operator() (int c,int d)
{
return (c<d);
}
}
mobjct;
int main ()
{
int mt[] = {32,71,12,45,26,80,53,33};
vector<int> mtr (mt, mt+8);
vector<int>::cerator e;
partial_sort (mtr.begin(), mtr.begin()+4);
cout << "mtr contains:";
for (e=mtr.begin(); e!=mtr.end(); ++e)
cout << " " << *e;
cout << endl;
return 0;
} Code: mtr contains: 12 26 32 33 45 53 71 80 |
|
#6
| ||||
| ||||
| Re: Use of the partial_sort() in CPP
The partial_sort can rearranges an elements into the given specified range [fst,lst), in such a way that the sub-range that can be [fst,mdl) can contains the elements that can be the smallest of the entire range that can be sorted in an ascending order and the sub-range that can be [mdl,nd) can contains the elements that can be remaining without any particular order. The elements that can be compared using an operator < for the first version, and cmp for the second version. |
![]() |
|
| Thread Tools | Search this Thread |
| |