求冒泡排序算法描述(c语言)!!谢!
thanks————————————————————————————————----
for(i=0;i<n;i++)
for(j=0;j<n-i;j++)
这是冒泡排序的关键循环语句,n代表所输数的个数。
#include <stdio.h> void sort_MP(int nbrs[],int length); int main(void){ int nbrs[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; int length = sizeof(nbrs)/sizeof(*nbrs); sort_MP(nbrs,length); for(int i = 0; i < length; i++){ printf("%d \t",nbrs[i]); } return 0; } void sort_MP(int nbrs[],int length){ int times = 0; int index = 0; int temp = 0; do{ index = 0; times = 0; LI: if(nbrs[index] < nbrs[index+1]){ temp = nbrs[index]; nbrs[index] = nbrs[index+1]; nbrs[index+1] = temp; times++; } index++; if(index < length-1) goto LI; length--; }while(times > 0); }