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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -