I'm trying to sort an array of numbers in ascending order and don't know whats wrong with my code (I'm completely new to vectors). I should first copy the input array (data) into an STL vector, then apply STL’s sorting algorithm to the vector, and finally copy the vector back into the array.
void STLSort(int data[],int size)
{
vector<int> a1;
a1.reserve(size);
for(int i=0;i<size;i++)
a1[i]=data[i];
sort(a1.begin(),a1.end());
for(int i=0;i<size;i++)
data[i]=a1[i];
}
Thanks.