#include<stdio.h> void maoPao(int arr[],int len){ int temp; //外循环 for (int i=0; i<len-1; i++) { //内循环 for (int j=0; j<len-2-i; j++) { //判断 if (arr[j]>arr[j+1]) { //如果大于则 交换数据 temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } } int main(int argc, const char * argv[]) { int a[10]={12,15,45,34,26,24,77,48,33,99}; maoPao(a, 10); for (int i=0; i<10; i++) { printf("%d\t",a[i]); } printf("\n"); return 0; } |