1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <algorithm>
#include <vector>
class Combo
{
int FinalLength ;
public:
//****************Printing *****************************
void Print(std::vector<int>& v)
{
for (size_t i =0 ; i < v.size() ; i++ )
{
std::cout << v[i] << std::endl ;
}
}
//*******************Taking arrays and Printing a sorted vector we created ***8
void Processing(int *a, int *b)
{
FinalLength = sizeof(a)/sizeof(a[0])+sizeof(b)/sizeof(b[0]); /*Error ! sizeof() ,doesn't work with the array being passed to this function ! */
int* p =new int[FinalLength];
std::copy(a,a+sizeof(a)/sizeof(a[0]),p);
std::copy(b,b+sizeof(b)/sizeof(b[0]),p+sizeof(a)/sizeof(a[0]));
//converting
std::vector<int>vec(p,p+FinalLength); //implementing the empty vector we created !
//sorting
sort( vec.begin(), vec.end() );
vec.erase( unique( vec.begin(), vec.end() ), vec.end() );
Print(vec);
}
};
int main()
{
//Why it works okay ,if I make everything inside main() ????
int a[] = {9,2,3,4,5,5,6,4,3,2,1};
int b[] = {212,21,32,412,5,5};
Combo obj ;
obj.Processing(a,b);
return 0 ;
}
|