泡沫排序法(法1):intlowest=0,temp=0; //ascendingsorting for(intj=0;j<total_item-1;j++) {lowest=j; for(inti=j+1;i<total_item;i++) if(a[i]<a[lowest]){ temp=a[i]; a[i]=a[lowest];a[lowest]=temp;//互換a[i]與a[lowest]之值;}}j=0à4,12,56,10,6 j=1à4,10,56,12,6à4,6,56,12,10 j=2à4,6,12,56,10à4,6,10,56,12j=3à4,6,10,12,56泡沫排序法(法2):intlowest=0,temp=0; //ascendingsorting for(intj=0;j<total_item-1;j++) {lowest=j; for(inti=j+1;i<total_item;i++) if(a[i]<a[lowest]) lowest=i; temp=a[j]; a[j]=a[lowest];a[lowest]=temp;//互換a[j]與a[lowest]之值;}12,4,56,10,6j=0à4,12,56,10,6 j=1à4,6,56,10,12 j=2à4,6,10,56,12j=3à4,6,10,12,56Quicksort(快速排序法)[12,4,56,{10},6,72,16]{10}4561267216 {10}4612567216 //endofforloop64{10}12567216 //swap(pStr,start,current);[{6}4]10[12{56}7216][{6}4]10[{56}127216][4{6}]10[{56}121672] //endofforloop[4]610[1612]56[72]4610[{16}12]56724610[{16}12]5672 //endofforloop4610[12]165672 461012165672
泡沫排序与快速排序法 来自淘豆网m.daumloan.com转载请标明出处.