Results 1 to 6 of 6

Thread: Use of the partial_sort() in CPP

  1. #1
    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.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    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. #3
    Join Date
    May 2008
    Posts
    2,012

    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. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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. #5
    Join Date
    May 2008
    Posts
    2,297

    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

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    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.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,483,125.83452 seconds with 15 queries