I need to move an index though an array to put an random array in order. Here is my code.
void insertNumber(int randomNum, int data[], int size)
{
int i = 0;
for(i = 0; randomNum > data[i] && i <= size - 2; i++)
{
}
for ( i = 0; i < 10; i++)
{
data[i+1] = data [i];
}
data[i] = randomNum;
}
Thank you for your time. It is an infinite loop I just don’t know how to fix it.
This looks like it’s going to overwrite everything from
data[0]todata[9]withdata[0]. I’m not sure if that’s what you’re trying to accomplish.Also,
is going to assign randomNum to
data[10]regardless of order. Perhaps we could get some more clarification on what you’re trying to do?