Results 1 to 6 of 6

Thread: The partial_sort_copy() function in C++

  1. #1
    Join Date
    Dec 2009
    Posts
    25

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

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

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

    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;
    }
    Output:
    Code:
    mvector contains: 1 2 3 4 5

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    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. #6
    Join Date
    Nov 2005
    Posts
    1,323

    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;
    }
    Program Output:
    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

Similar Threads

  1. c++ equivalent function to the c-function 'sprintf
    By Dilbert in forum Software Development
    Replies: 6
    Last Post: 13-12-2011, 04:03 PM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  4. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  5. Function keys don't function under windows XP
    By GunFighter in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-04-2009, 11:07 PM

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,726,894,985.16799 seconds with 17 queries