forked from TheAlgorithms/C
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request TheAlgorithms#18 from theycallmemac/patch-7
Rename OtherBubbleSort.c to Sorts/OtherBubbleSort.c
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#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; | ||
|
||
|
||
/* For example | ||
Insertion random values in array to test | ||
*/ | ||
|
||
|
||
for(i = 0 ; i < MAX; i++) | ||
{ | ||
arraySort[i] = rand()%101 ; | ||
} | ||
|
||
|
||
/* Algorithm of bubble methods */ | ||
|
||
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; | ||
} | ||
|
||
} | ||
} | ||
|
||
/* See if it works */ | ||
|
||
for(i = 0 ; i < MAX; i++) | ||
{ | ||
printf("%d\n", arraySort[i]); | ||
} | ||
|
||
|
||
|
||
|
||
return EXIT_SUCCESS; | ||
|
||
} |