Results 1 to 6 of 6

Thread: What is use of the merge() function in C++

  1. #1
    Join Date
    Jan 2010
    Posts
    29

    What is use of the merge() function in C++

    I am working in the ABC company as software developer. We can use the C++ language for developing the software. Hence, I can not know about the merge() function of the C++ language. So, I would like to know about the merge() function of the C++ language. I also would like to know about what is the use of the merge() function of the C++ language. Can anyone has the solution for me then reply!!!!

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

    The merge() function in C++

    The merge() function can be used in the C++ language to merge the ranges that can be sorted. The merge() function can combines an elements in the ranges that can be sorted [fst1,lst1) and [fst2,lst2), into a new range that can beginning at result with its elements that can be sorted. The comparison that can be used for sorting can uses either operator "<" for the first version or comp for the second version.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    What is use of the merge() function

    The merge() function of the can be used in the C++ language to merge the ranges that can be sorted. The following can be the syntax of the merge() function in the C++ language :
    Code:
    template <class InptItrtr1, class InptItrtr12, class OtptItrtr>
      OtptItrtr merge ( InptItrtr11 fst1, InptItrtr11 lst1,
                             InptItrtr12 fst2, InptItrtr12 lst2,
                             OtptItrtr rslt );

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    What is use of the merge() function in C++

    The following program can demonstrates you how to use the merge() function of the C++ language in the C++ coding as follows :
    Code:
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int main ()
     {
      int fst[] = {5,10,15,20,25};
      int scnd[] = {50,40,30,20,10};
      wector<int> w(10);
      wector<int>::terator t;
      sort (fst,fst+5);
      sort (scnd,scnd+5);
      merge (fst,fst+5,scnd,scnd+5,w.begin());
      cout << "The resulting wector contains:";
      for (t=w.begin(); t!=w.end(); ++t)
      cout << " " << *t;
      cout << endl;
      return 0;
    }
    Output:
    Code:
    The resulting wector contains: 5 10 10 15 20 20 25 30 40 50

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

    Re: What is use of the merge() function in C++

    The following can be the parameters of the merge() function of the C++ language :
    1. fst2, lst2 : These parameter of the merge() function can contains the Input iterators to the final and starting positions of the second sequence. The range used can be [fst2,lst2).
    2. rslt : This parameter of the merge() function can contains an output iterator to the starting position of the given specified range where the resulting range that can be combined can be stored. Its length can be equal to the addition of the lengths of both of the given previous ranges.
    3. fst1, lst1 : These parameter of the merge() function can contains input iterators to the final and starting positions of the first given sequence. The range used can be [fst1,lst1).

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

    merge() function in C++

    PROGRAM :
    Code:
    #include <iostream>
    #include <algorithm>
    using std::cout;
    using std::endl;
    int main()
    {
       int s1[ 5 ] = { 1, 3, 5, 7, 9 };
       int s2[ 5 ] = { 2, 4, 5, 7, 9 };
       std::vector< int > w1( s1, s1 + 5 );
       std::vector< int > w2( s2, s2 + 5 );
       std::iostream_iterator< int > output( cout, " " );
       std::copy( w1.begin(), w1.end(), output ); 
       cout << "\n\n";
       std::copy( w2.begin(), w2.end(), output ); 
       std::vector< int > rslts2( w1.size() + w2.size() );
       std::merge( w1.begin(), w1.end(), w2.begin(), w2.end(), rslts2.begin() );
       cout << "\n\n After merge of w1 and w2 rslts2 contains:\n";
       std::copy( rslts2.begin(), rslts2.end(), output );
       cout << endl;
       return 0;
    }
    OUTPUT :
    Code:
    1 3 5 7 9
    
    2 4 5 7 9
    
    After merge of w1 and w2 rslts2 contains:
    1 2 3 4 5 5 7 7 9 9

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,855,254.20452 seconds with 17 queries