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