Created
January 2, 2014 13:37
-
-
Save novnan/8219277 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> | |
#define N 100 | |
void main() | |
{ | |
int iData[N]; | |
int *p; | |
int i, j, n, t; | |
printf("共有几个数(1~%d):", N); | |
scanf("%d", &n); | |
printf("它们是:"); | |
for(p = iData; p < iData + n; p++) | |
{ | |
scanf("%d", p); | |
} | |
for(i = 0; i < n - 1; i++) //起泡法排序 | |
{ | |
for(j = n - 1; j > i; j--) | |
{ | |
if(*(p + j - 1) > *(p + j)) | |
{ | |
t = *(p + j); | |
*(p + j) = *(p + j - 1); | |
*(p + j - 1) = t; | |
} | |
} | |
} | |
printf("排序后:"); | |
for(p = iData; p < iData + n; p++) | |
{ | |
printf("%d\t", *p); | |
} | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment