
程序代码:
#include <stdio.h>
void bubblesort(int *p, int len)
{
int temp;
for (int i = 0; i < len - 1; i++)
{
for (int j = 0;j < len - 1; j++)
{
if (*(p + j) > *(p + j + 1))
{
temp = *(p + j);
*(p + j) = *(p + j + 1);
*(p + j + 1) = temp;
}
}
}
}
int main(void)
{
int i, len, *p;
int arr[6] = { 9,8,5,4,2,0 };
p = arr;
len = sizeof(arr) / sizeof(int);
bubblesort(p, len);
for (i = 0; i < 6; i++)
printf("%d ",arr[i]);
printf("\n");
return 0;
}