Lập Trình C/C++ - STL Merge

#Code:
#include<iostream>
#include<algorithm>
#include<iterator>
using namespace std;

/* Preprocessor */
#define get_size(array) (sizeof((array))/sizeof((array[0])))

template<class t>
class merge_array
{
 public:
  merge_array(t *list1, int size1, t *list2, int size2)
  {
   /* Merge two array and print */
   merge (list1, list1+size1, list2, list2+size2, ostream_iterator(cout," "));
   cout << "\n" << endl;
  }
};


int main()
{
 /* Merge int */
 int array1[] = { 1, 2, 2, 4, 6, 7, 7, 9 };
 int array2[] = { 3, 2, 2, 3, 6, 6, 8, 9 };
 merge_array mrg1(array1,get_size(array1), array2, get_size(array2));

 /* Merge float */
 float array3[] = { 1.11, 2.35, 2.21, 4.51, 6.62, 7.75, 7.52, 9.11 };
 float array4[] = { 221, 2.11, 2.44, 3.55, 6.21, 6.50, 8.51, 9.21 };
 merge_array mrg2(array3,get_size(array3), array4, get_size(array4));

 /* Merge string */
 string array5[] = { "c", "java", "programming", "css", "css3", "perl", "javascript", "php" };
 string array6[] = { "c++", "python", "html", "html5", "ruby", "assembly", "jquery", "cgi" };
 merge_array mrg3(array5,get_size(array5), array6, get_size(array6));

 return 0;
}

0 Comment:

Đăng nhận xét

Thank you for your comments!