使用指针实现冒泡排序的数组元素升序排列。
#include<stdio.h>void bubarray(int a[], int n);int main(void){int a[] = {0,-1,-2,4,3,1,20,15 };int n = (int)sizeof(a) / sizeof(a[0]);printf("Initial results:\n");for (int i = 0; i < n; i++)printf("%d ", a[i]);printf("\n");bubarray(a, n);return 0;}void bubarray(int a[], int n){int i, j, Temp;for(i=0;i<n;i++)for (j = n - 1; j >= i; j--){if (a[i] > a[j]){Temp = a[j];a[j] = a[i];a[i] = Temp;}}printf("The endP:\n");for (int i = 0; i < n; i++)printf("%d ", a[i]);printf("\n");}
如果觉得《使用指针实现冒泡排序的数组元素升序排列》对你有帮助,请点赞、收藏,并留下你的观点哦!