Created
June 16, 2012 13:34
-
-
Save tdkn/2941346 to your computer and use it in GitHub Desktop.
aoj 10004
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> | |
// define macro | |
#define swap(type, x, y) do {type t = x; x = y; y = t;} while(0) | |
// define prototype | |
void bubble_sort(int a[], int n); | |
// main program | |
int main(void) | |
{ | |
int i; | |
int arr[3]; | |
int num = sizeof(arr) / sizeof(arr[0]); | |
scanf("%d %d %d",&arr[0], &arr[1], &arr[2]); | |
bubble_sort(arr, num); | |
printf("%d %d %d\n", arr[0], arr[1], arr[2]); | |
// added 2012-06-16 22:57 | |
// return 忘れてて RE 出てたのね | |
return 0; | |
} | |
// sort program | |
void bubble_sort(int a[], int n) | |
{ | |
int i, j; | |
for(i = 0; i < n - 1; i++) { | |
for (j = n - 1; j > i; j--) { | |
if(a[j -1] > a[j]) { | |
swap(int, a[j - 1], a[j]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment