C語言 冒泡排序 遞迴法

來源:互聯網
上載者:User

標籤:tar   blog   輸入   lin   view   image   lib   alt   排序   

 1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5      6     void bubble(int *a,int n); 7      8     int i,n,a[100]; 9     10     printf("請輸入數組中元素數量(不大於100個):");11     scanf("%d",&n);12     13     for(;n<1||n>100;){14         printf("元素數量超出範圍,請重新輸入:");15         scanf("%d",&n);        16     }printf("\n");17     18     for(i=0;i<n;i++){19         printf("請輸入元素a[%d]:",i);20         scanf("%d",&a[i]);21     }printf("\n");22     23     printf("您輸入了以下元素:\n");24     for(i=0;i<n;i++){25         printf("%d ",a[i]);26     }printf("\n\n");27     28     bubble(a,n);29     30     printf("遞增排列為:\n");31     for(i=0;i<n;i++){32         printf("%d ",a[i]);33     }printf("\n");34     35     system("pause");36     return 0;37 }38 39 void bubble(int *a,int n)40 {41     int i;42     if(n==1){43         return;44     }45     for(i=0;i<n-1;i++){46         if(a[i]>a[i+1]){47             int t=a[i];a[i]=a[i+1];a[i+1]=t;48         }        49     }50     bubble(a,n-1);51 }
View Code

 

C語言 冒泡排序 遞迴法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.