Created
May 18, 2014 14:37
-
-
Save kimitoboku/76bb45a1ba7ca50c276e to your computer and use it in GitHub Desktop.
bubblesort
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 bubblesort(int array[],int n){ | |
int i; | |
for(i=n-1;i!=0;i--){ | |
int index; | |
for(index = 0; index < i ;index++){ | |
if(array[index] > array[index+1]){ | |
int n = array[index]; | |
array[index] = array[index+1]; | |
array[index+1] = n; | |
} | |
} | |
} | |
} | |
int main(void){ | |
int array[100]; | |
int n; | |
scanf("%d",&n); | |
int i; | |
for(i=0;i<n;i++){ | |
scanf("%d",&array[i]); | |
} | |
bubblesort(array,n); | |
for(i=0;i<n;i++){ | |
printf("%d ",array[i]); | |
} | |
puts(""); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment