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: 26
The inplace_merge() of C++

Hi, How are you!! I am the studying in the BSC-IT first year. I can have learn the C++ language. I can know the concept of functions. I can learn the functions in the first semester of the BSC-IT in the C language. So, I would like to know about the inplace_merge() function of the C++ language. I also would like to know about what is the use of the inplace_merge() function of the C++ language. Anyone can help me to know about the inplace_merge() function of the C++ language, Reply Me!!!
Reply With Quote
  #2  
Old 03-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: The inplace_merge() of C++

The inplace_merge() function of the C++ language can be used to merge consecutive given specified ranges that can be sorted. The following can be the general form of the inplace_merge() function of the C++ language as :
Code:
template <class BidrctnlItrtr>
  void inplace_merge ( BidrctnlItrtr fst, BidrctnlItrtr mdl,
                       BidrctnlItrtr lst );
Reply With Quote
  #3  
Old 03-03-2010
Member
 
Join Date: Nov 2005
Posts: 1,323
The inplace_merge() of C++

The following program can demonstrates you how to implement the inplace_merge() function of the C++ language in the C++ programming as follows :
Code:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main () 
{
  int fst[] = {5,10,15,20,25};
  int scnd[] = {50,40,30,20,10};
  vector<int> w(10);
  vector<int>::iterator it;
  sort (fst,fst+5);
  sort (scnd,scnd+5);
  copy (fst,fst+5,w.begin());
  copy (scnd,scnd+5,w.begin()+5);
  inplace_merge (w.begin(),w.begin()+5,w.end());
  cout << "The resulting vector contains:";
  for (it=w.begin(); it!=w.end(); ++it)
  cout << " " << *it;
  cout << endl;
  return 0;
}
Output:
Code:
The resulting vector contains: 5 10 10 15 20 20 25 30 40 50
Reply With Quote
  #4  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: The inplace_merge() of C++

The following can be the parameters of the inplace_merge() function of the C++ language as :
1. mdl : This parameter of the inplace_merge() function can contains bidirectional iterator to the starting position of the given second sequence that can because both the sequences can be similar in the sequence that can matches the past-the-end position of the first sequence.
2. lst : This parameter of the inplace_merge() function can contains bidirectional iterator to the final position of the given sequence that can be second. This can be also the final position in the resulting range that can be merged can be stored.
3. fst : This parameter of the inplace_merge() function can contains bidirectional iterator to the starting position in the first sequence that can be merged. This can be also the starting position of where the resulting range can be merged can be stored.
Reply With Quote
  #5  
Old 03-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: The inplace_merge() of C++

This can be one more example for you that can states you what is the use and how to use the inplace_merge() function in the C++ programming as follows :
Code:
#include <functional>   
#include <iostream> 
#include <iterator> 
#include <vector>
int main ()
{
typedef std::vector<int, std::allocator<int> > Vector;
const Vector::value_type d1[] = { 1, 2, 3, 4};
const Vector::value_type d2[] = { 11, 13, 15, 17, 
  12, 14, 16, 18};
Vector v1 (d1 + 0, d1 + sizeof d1 / sizeof *d1);
Vector v2 (d1 + 0, d1 + sizeof d1 / sizeof *d1);
Vector v3 (d2 + 0, d2 + sizeof d2 / sizeof *d2);
Vector v4 (v3);
Vector v5 (v3);
Vector v6 (v3);
Vector v7;
std::merge (v1.begin (), v1.end (),
v2.begin (), v2.end (), v3.begin ());
std::merge (v1.begin (), v1.end (),
v2.begin (), v2.end (), v4.begin (), 
std::less<int>());
Vector::iterator mid = v5.begin ();
std::advance (mid, 4);
std::inplace_merge (v5.begin (), mid, v5.end ());
mid = v6.begin ();
std::advance (mid, 4); 
std::inplace_merge (v6.begin (), mid, v6.end (), 
std::less<int>());
std::merge (v1.begin (), v1.end (),
v2.begin (), v2.end (), 
std::back_inserter (v7));
std::ostream_iterator<int, char, std::char_traits<char> >
  out (std::cout," ");
std::copy (v1.begin (), v1.end (), out);
std::cout << std::endl;
std::copy (v2.begin(), v2.end (), out);
std::cout << std::endl;
std::copy (v3.begin (), v3.end (), out);
std::cout << std::endl;
std::copy (v4.begin (), v4.end (), out);
std::cout << std::endl;
std::copy (v5.begin (), v5.end (), out);
std::cout << std::endl;
std::copy (v6.begin (),v6.end (), out);
std::cout << std::endl;
std::copy (v7.begin (), v7.end (), out);
std::cout << std::endl;
std::merge (v1.begin (), v1.end (), 
v2.begin (), v2.end (), out);
return 0;
}
Program Output:
Code:
1 2 3 4 
1 2 3 4 
1 1 2 2 3 3 4 4 
1 1 2 2 3 3 4 4 
11 12 13 14 15 16 17 18 
11 12 13 14 15 16 17 18 
1 1 2 2 3 3 4 4 
1 1 2 2 3 3 4 4

Last edited by kelfro : 03-03-2010 at 10:23 PM.
Reply With Quote
Reply

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 06:12 PM.