Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Use of the partial_sort() in CPP

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-02-2010
Member
 
Join Date: Dec 2009
Posts: 33
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.
Reply With Quote
  #2  
Old 25-02-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
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 );
Reply With Quote
  #3  
Old 25-02-2010
Member
 
Join Date: May 2008
Posts: 1,990
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).
Reply With Quote
  #4  
Old 25-02-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
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;
}
Reply With Quote
  #5  
Old 25-02-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
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;
}
The output of the above program can be :
Code:
mtr contains: 12 26 32 33 45 53 71 80
Reply With Quote
  #6  
Old 25-02-2010
absolute55's Avatar
Member
 
Join Date: Nov 2005
Posts: 1,238
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 03:51 AM.