C语言 冒泡排序
#include <stdio.h>
#include <stdlib.h>
void bubbleSort(int *arr
,int n
)
{
int temp
, i
, j
;
for(i
= 0; i
< n
- 1; i
++)
for(j
= 0; j
< n
- 1 - i
; j
++)
if(arr
[j
] > arr
[j
+1])
{
temp
= arr
[j
];
arr
[j
] = arr
[j
+1];
arr
[j
+ 1] = temp
;
}
}
int main(void)
{
int p
[10] = {1, 5, 3, 4, 8, 10, 4, 6, 7, 2};
int i
;
bubbleSort(p
, 10);
for(i
= 0; i
< 10; i
++)
{
printf("%d ", p
[i
]);
}
system("pause");
return 0;
}
转载请注明原文地址:https://tech.qufami.com/read-17698.html