Hi,
Seems you want to achieve something like:
#include <vector>
#include<iostream>
#include <iterator>
#include <algorithm>
int main()
{
using std::cin;
using std::cout;
using std::endl;
std::vector<int> vals;
int nVals = {0};
do
{
cout << "Enter the number of values :" << endl;
if (cin >> nVals && (nVals > 0))
{
cout <<"Enter " << nVals << " values:"<< endl;
std::copy_n(std::istream_iterator<int>(cin), nVals, std::back_inserter(vals));
std::sort(vals.end() - nVals, vals.end());
cout << "Values: ";
std::copy(vals.end() - nVals, vals.end(), std::ostream_iterator<int>(cout, " "));
cout << endl;
}
} while (cin && (nVals > 0));
std::sort(vals.begin(), vals.end());
cout << "All sorted values: ";
std::copy(vals.begin(), vals.end(), std::ostream_iterator<int>(cout, " "));
cout << endl;
return 0;
}
Use the Standard C++ Library containers and algorithms to avoid painful and error prone index handling, and miserable sort and merge attempts.
cheers,
AR