Created
May 12, 2014 03:59
-
-
Save dd1994/c2631ffabf08ec28a27f 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 input(int *, int); | |
void output(int *, int); | |
void swap(int *, int *); | |
void sort(int *, int); | |
int main(void) | |
{ | |
int a[100], n; | |
while(scanf("%d", &n) != EOF) { | |
input(a, n); | |
sort(a, n); | |
output(a, n); | |
} | |
return 0; | |
} | |
void input(int *a, int n) | |
{ | |
int i; | |
for (i = 0; i < n; ++i) | |
{ | |
scanf("%d", a + i); | |
} | |
} | |
void output(int *a, int n) | |
{ | |
int i; | |
for (i = 0; i < n - 1; ++i) | |
{ | |
printf("%d ", a[i]); | |
} | |
printf("%d\n",a[n-1]); | |
} | |
void sort(int *a, int n) | |
{ | |
int i, j, temp; | |
for (i = 0; i < n - 1; ++i) | |
{ | |
for (j = i + 1; j < n; ++j) | |
{ | |
swap(&a[i], &a[j]); | |
} | |
} | |
} | |
void swap(int *p1, int *p2) | |
{ | |
int temp; | |
if(*p1 > *p2) | |
{ | |
temp = *p1; | |
*p1 = *p2; | |
*p2 = temp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment