冒泡排序(C语言)

#include <stdio.h>

void bubbleSort(int *numberPointer,int numbers)/*接口:排序数组首地址,数组个数(int 型)*/ {
	int i, j,middle=0;
	for (i = 0; i < numbers; i++) {
		for (j = 0; j < numbers - i-1; j++) {
			if (*(numberPointer + j) >/* > 从小到大 < 从大到小 */*(numberPointer + j + 1)) {
				middle = *(numberPointer + j);
				*(numberPointer + j) = *(numberPointer + j + 1);
				*(numberPointer + j + 1) = middle;
			}
		}
	}
}


void main() {
	int sum[10] = { 74,894,24,654,1,12,464,548,56486,545615 };
	int i;
	bubbleSort(&sum[0], 10);
	for (i = 0; i < 10; i++)
		printf("%-10d", sum[i]);
	system("pause");
}
	运行结果:1         12        24        74        464       548       654       894       56486     545615 
posted @ 2022-01-23 14:11  tothk  阅读(35)  评论(0编辑  收藏  举报