So I need to sort an vector, and instead of doing things by hand i am using insert and erase.
so far my code is
for (int x = 0; x < arr.size(); x++) {
for (int y = x; y < arr.size(); y++)
{
if ( arr[y] < arr[x])
{
arr.insert(arr.begin()+x,arr[y]);
arr.erase(arr.begin()+y+1);
}
}
}
and yet when it runs I get time outs in my test cases and works for like 3 of them (test cases being 245+ integers of long numbers). I have to use vectors and have to use insertion sort as part of the design (finds minimum swaps to sort but thats cut from here), which i know has bad runtime.
What am I doing wrong here for the compiler to act like this?