How can I sort these two arrays? (elements will enter by user)

I want to sort the first array to find common elements. help me to sort by the best way ;) first the user enters the length of Array1 and then enter elements for Array1 second enter the length of Array2 (it should be smaller than length of Array1) and then enter elements of Array2. finally I want to sort Array1 find common elements. " Which way is easier to sort then? "

And also is my check function logically correct?!!
#include "stdafx.h"
#include <iostream>
using namespace std;

void check (int[], int[]);


int _tmain(int argc, _TCHAR* argv[])
{   
    int n1, n2, arr1[50], arr2[50];
        cout << " How many elements you want to enter to Array 1 : ";
        cin >> n1;
    for(int i=0; i<n1; i++)
    {
        if (n1 >= 50)
            cout << " your input is more than MAX !!! " << endl;
        else
            cout << " Enter elements " << "[" << i <<"]: ";
            cin >> arr1[i];
    }
        cout << endl;
        cout << " How many elements you want to enter to Array 2 : ";
        cin >> n2;
        if (n2 >= n1)
            cout << " your input is more than Array 1 !!! " << endl;
        else {
    for (int j=0; j<n2; j++)
    {
        cout << " Enter elements " << "[" << j << "]: ";
        cin >> arr2[j];
    }

    for (int i=0; i<n1; i++)
        cout << arr1[i] << "\t";
    cout << endl;
    for (int j=0; j<n2; j++)
        cout << arr2[j] << "\t";
        }
    cout << endl;

    check (arr1, arr2);

    system ("pause");
    return 0;
}

void check (int x[], int y[])
{
    int temp;
    cout << " Common elements are: " << endl;
    for ( int i=0; i<y[i]; i++ )
    {
        if (x[i] == y[i])
            temp = x[i];
        cout << temp << "\t";   
    }
    cout << endl;
}

Answers


add

#include <algorithms>

now you can easily sort the elements as

std::sort(arr,arr+arr_length);

Also where are you storing the elements in the array?


Need Your Help

Get the table name as dynamically in ssis

ssis-2012

I have a table in that table i'm inserting all my TableNames of that database.

CFReadStreamCopyError report error on iPad device

iphone objective-c nsstream

I am running into an issue. Same code running OK on iPhone (iOS 5) and iPhone/iPad simulator. But it does not work on an iPad (iOS 5). I'd appreciate any help.