dimanche 12 juillet 2020

this code work with N=348 but dont work when N = 349

why dose this sorting code work with N=348 but when N=349 program hang.?there is not compilation error.

#define N 348
int main(void){
  int n[N];
  int temp;

  for(int i=0;i<N;i++) n[i] = rand();

  for(int i=0 ; i<N-1;){
    if (n[i]<n[i+1]) {i++;continue;}
    else {
       temp = n[i];
       n[i] = n[i+1];
       n[i+1] = temp;
       if (i != 0) i--;
       else i++;
    }
  }

  return 0;
}

Aucun commentaire:

Enregistrer un commentaire