oj 2647: 冒泡排序法排序

問題:

Description

給定一組數據,用冒泡法排序(10個)

遞增排序

Input

10個整型數據

Output

排序後的數列

Sample Input

5 8 9 7 4 6 3 1 2 0

Sample Output

0 1 2 3 4 5 6 7 8 9 

HINT

Source

代碼:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a[10];
    int i,j,t;
    for(i=0; i<10; i++)
        scanf("%d",&a[i]);
    for(i=0; i<10; i++)
        for(j=0; j<10-i-1; j++)
        {
            if(a[j]>a[j+1])
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    for(i=0; i<10; i++)
        printf("%d ",a[i]);
    return 0;
}

小結:最基礎的排序算法,你,值得擁有!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章