冒泡排序(指针)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_43909184/article/details/90136642
#include<stdio.h> 
int main() {
	int a[] = { 4,2,6,7,8,1,0 };
	int n = sizeof(a) / sizeof(a[0]);
	int *p = a, *q = a + 1, *end = a + n - 1;
	int tmp;
	for (p = a; p < a + n - 1; ++p) {
		for (q = a; q < end; ++q) {
			if (*q < *(q + 1)) {
				tmp = *q;
				*q = *(q + 1);
				*(q + 1) = tmp;
			}
		}
		end--;
	}
	for (int i = 0; i < n; ++i) {
		printf("%d ", a[i]);
	}
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43909184/article/details/90136642