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

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-03-2010
Member
 
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!!!!
Reply With Quote
  #2  
Old 03-03-2010
Member
 
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.
Reply With Quote
  #3  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 2,008
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 );
Reply With Quote
  #4  
Old 03-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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
Reply With Quote
  #5  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 2,293
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).
Reply With Quote
  #6  
Old 03-03-2010
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is use of the merge() function in C++"
Thread Thread Starter Forum Replies Last Post
c++ equivalent function to the c-function 'sprintf Dilbert Software Development 6 13-12-2011 04:03 PM
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 10:44 PM
How to pass function with parameters to another function in PHP? Linoo Software Development 5 27-02-2010 07:52 PM
How does abstract function differs from virtual function? Maddox G Software Development 5 29-01-2010 11:32 AM
Function keys don't function under windows XP GunFighter Hardware Peripherals 3 08-04-2009 11:07 PM


All times are GMT +5.5. The time now is 05:51 PM.