why this shift function dont work?

To add comments, please log in or register
pedro de
60
pedro de  
 void Shift(double &array[], double element){
 
 int array_size = ArrayRange(array,0);
 
 for(int j=array_size-1;j>0;j--){array[j] = array[j-1];};
 
 array[0] = element;
  

all indexes positions receive the same value, i think this will be a problem if i make the sort in other direction (array[j+1]=array[j]) but this way i cant find a reason

Naguisa Unada
504
Naguisa Unada  

How about this one?

void Shift(double &array[], double element)
{
   int array_size = ArrayRange(array, 0);

   for(int j = array_size - 1; j > 0; j--) 
   {
        array[j] = array[j - 1];
   }

   array[0] = element;
}
To add comments, please log in or register