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;
}

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