找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1850|回复: 0
收起左侧

静态冒泡排序

[复制链接]
ID:291571 发表于 2018-3-13 23:35 来自触屏版 | 显示全部楼层 |阅读模式

# include <stdio.h>
int fun(int a[])
{
        int i = 0;
        int j = 0;
        int temp = 0;
        for (i = 0; i < 5; i++)
        {
                for (j = 0; j < 5-i-1; j++)
                {
                       
                        if (a[j] > a[j+1])
                        {
                                temp = a[j];
                                a[j] = a[j+1];
                                a[j+1] = temp;
                        }
                }
        }
        for (i=0;i<5;i++)
        {
                printf("%d ", a[i]);
        }
        return 0;

}
int main()
{
        int a[] = { 18,12,3,15,7 };
        fun(a);
        system("pause");
        return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表