arrays - Time limit exceeded in bubble sort -
arrays - Time limit exceeded in bubble sort -
problem-to sort array in ascending order algorithm used-bubble sort error-time limit exceeded compiler-ideone online editor /codeblocks possible alternative this?
int a[5]; int i,t,j; for(i=0;i<=4;i++) //for initialising elements { printf("enter 5 numbers"); scanf("%d",&a[i]); } for(j=0;j<5;i++) //for sorting { for(i=0;i<5;i++) { if(a[i]>a[i+1]) { t=a[i+1]; a[i+1]=a[i]; a[i]=t; } } } for(i=0;i<=4;i++) //for printing sorted array { printf("%d\n",a[i]); }
your loop:
for(j=0;j<5;i++) //for sorting
should j++, should be
for(j=0;j<5;j++)
your sec loop:
for(i=0;i<5;i++)
should
for(i=0;i<4;i++)
arrays sorting bubble-sort
Comments
Post a Comment