code cleanup & fixed syntax error

This commit is contained in:
Krishna Vedala 2020-04-07 18:29:24 -04:00
parent a3989bbadc
commit cee2468506
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
1 changed files with 24 additions and 33 deletions

View File

@ -1,56 +1,47 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define MAX 20 #define MAX 20
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
int main() int main()
{ {
int i , arraySort[MAX] ={0} , isSort = FALSE, changePlace; int i, arraySort[MAX] = {0}, isSort = FALSE, changePlace;
/* For example
/* For example
Insertion random values in array to test Insertion random values in array to test
*/ */
for (i = 0; i < MAX; i++)
for(i = 0 ; i < MAX; i++)
{ {
arraySort[i] = rand()%101 ; arraySort[i] = rand() % 101;
} }
/* Algorithm of bubble methods */ /* Algorithm of bubble methods */
while(isSort) while (isSort)
{ {
isSort = FALSE; isSort = FALSE;
for( i = 0 ; i < MAX - 1 ; i++) for (i = 0; i < MAX - 1; i++)
{ {
if(arraySort[i] > arraySort[i+1]) if (arraySort[i] > arraySort[i + 1])
{ {
changePlace = arratSort[i]; changePlace = arraySort[i];
arraySort[i] = arraySort[i+1]; arraySort[i] = arraySort[i + 1];
arraySort[i+1] = changePlace ; arraySort[i + 1] = changePlace;
isSort = TRUE; isSort = TRUE;
} }
}
}
} }
/* See if it works */ /* See if it works */
for(i = 0 ; i < MAX; i++) for (i = 0; i < MAX; i++)
{ {
printf("%d\n", arraySort[i]); printf("%d\n", arraySort[i]);
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }