Skip to content

Instantly share code, notes, and snippets.

@novnan
Created January 2, 2014 13:37
Show Gist options
  • Save novnan/8219277 to your computer and use it in GitHub Desktop.
Save novnan/8219277 to your computer and use it in GitHub Desktop.
// 用起泡法排序
#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