Created
April 3, 2018 15:55
-
-
Save ming2540/e56bfb5c943663d4b12de8dbb3bd506f to your computer and use it in GitHub Desktop.
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
#include<stdio.h> | |
void bubble_sort(int data[], int data_number){ | |
int i,j,temp; | |
for(i=0 ; i < data_number ; i++)//until done sorting | |
for(j=0; j < data_number-1 ; j++) // for one time | |
if(data[j] > data[j+1]){ | |
//swap data | |
temp = data[j]; | |
data[j] = data[j+1]; | |
data[j+1] = temp; | |
} | |
} | |
int main(){ | |
int data[6] = {5,3,4,6,2,7}; | |
int i,j; | |
printf("Unsorted data : "); | |
for(i=0 ; i < 6 ; i++) | |
printf("%d ",data[i]); | |
printf("\n"); | |
bubble_sort(data , 6); | |
printf("Sorted data : "); | |
for(i=0 ; i < 6 ; i++) | |
printf("%d ",data[i]); | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment