排序演算法00_冒泡排序

來源:互聯網
上載者:User

標籤:迴圈   sort   ted   numbers   clu   stdio.h   include   int   冒泡排序   

1、普通冒泡排序
 1 //冒泡排序 2 #include<stdio.h> 3 int main(){ 4     int a[10],i,j,t; 5     printf("enter 10 numbers:");     6     for(i=0;i<10;i++){ 7         scanf("%d",&a[i]); 8     } 9     //數組中有n個數,依次找出n-1個較大數,所以外層迴圈的迴圈次數為n-110     for(i=0;i<9;i++){11     //每一輪比較中,共進行j次比較,j從0開始迴圈,第0次迴圈(n-1)-0次;12     //第1次迴圈(n-1)-1次;第i次迴圈,迴圈(n-1)-i次                                                                                                                13         for(j=0;j<9-i;j++){14             if(a[j]>a[j+1]){15                 t=a[j+1];a[j+1]=a[j];a[j]=t;16             }17         }18     }19     printf("the sorted numbers:");20     for(i=0;i<10;i++){21         printf("%3d",a[i]);22     }23     return 0;24 }

 

排序演算法00_冒泡排序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.