zoukankan      html  css  js  c++  java
  • 算法之【冒泡排序法】

    冒泡排序法是一种较简单的数值大小排序的算法。主要逻辑是:

    对于原始的一组线性数据,从头到尾依次两两比较,如果前者大于后者(或者相反)则交换两个数的位置。这样一遍做下来,数组最末端即是所有数中最大的(或最小的),接下来将除了最后一个数以外剩下的数据再进行一遍刚才的算法。以此类推,每一遍的数据都越来越少,直到最后只剩一个时结束,此时排序完成。

    Bubble Sort is a simple algorithm ofsequencing a pile of data, especially numerical numbers. The main method is:

    In terms of a set of linear data, compare every two data from the beginning to the end, if the former one is greater than the latter one (or vice versa), swap the two’s position. Now the biggest (or smallest) of all is at the end of the array, then operate the remaining data (except the last one) using the same way as before. By analogy, and each time the data we work on is less and less, stop until there is only one data. Now all things have completed.

    Void bubble_sort(int a[],int n)

    {

        Int i,j,temp;

        for (j=0;j

            for(i=0;i

            {

                if(a[i]>a[i+1])

                {

                    temp=a[i];

                    a[i]=a[i+1];

                    a[i+1]=temp;

                }

            }

    }


  • 相关阅读:
    到底该不该熟悉掌握struts2的ONGL呢?
    struts2 request内幕 为什么在struts2用EL表达式可以取值
    struts2 权限拦截器 拦截没有登陆的请求
    tomcat context 配置 项目部署
    tomcat 设置默认编码格式
    工作记录1
    javascript 的学习笔记(第一天)
    JavaScript for...in 循环
    indexof方法区分大小写
    java 和 IntelliJ IDEA 的一些配置
  • 原文地址:https://www.cnblogs.com/jinhengyu/p/7517109.html
Copyright © 2011-2022 走看看