Bubble sort,It's a relatively basic algorithm.The core implementation ideas are as follows:

1.Define an array,The length is N.

2.Compares each pair of adjacent items and swaps them if they are in the wrong order.

 such as:

   if (a[j - 1] > a[j]) {//The number in front is larger than that in the back.                 //swap a[j-1]和a[j]    int temp;       //Initial value of definition temp.    temp = a[j - 1];    a[j - 1] = a[j];    a[j] = temp;

3.N=N-1,If N is not 0, repeat the previous two steps, otherwise the sorting is completed.

Implementation:

utility class:

public class BubbleSort {  public static void mian(String args[])      {       //ToDo      }
    public static <T extends Comparable<? super T>>void bubbleSort (T[]arr){        int n = arr.length;        int boundary;//Trailing edge traversal of records.        do {            boundary = 0;            for (int i = 1; i < n; i++)                if (arr[i - 1].compareTo(arr[i]) > 0) {                    swap(Arrays.asList(arr), i - 1, i);                    boundary = i;//The boundary value is reset after each comparison, and if this line is not executed during the comparison, the sorting is done.                }            n = boundary;        } while (boundary > 0);    }}

implementation class:

class Numbers implements Comparable<Numbers>{    private int number;    public int getNumber(){        return number;    }    public void setNumber(){        this.number=number;    }    public Numbers(int number){        super();        this.number=number;    }    @Override  public String toString(){        return "[number="+number+"]";    }    @Override    public int compareTo(Numbers o) {        if(number==o.number)            return 0;        else if(number>o.number)            return 1;        else            return -1;

    }}

Over.

Thanks.2018-09-24.

 



Bubble sort of sorting algorithm的更多相关文章

  1. POJ3761 Bubble Sort (组合数学,构造)

    题面 Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be ...

  2. 排序算法 (sorting algorithm)之 冒泡排序(bubble sort)

    http://www.algolist.net/Algorithms/ https://docs.oracle.com/javase/tutorial/collections/algorithms/ ...

  3. [Algorithms] Sorting Algorithms (Insertion Sort, Bubble Sort, Merge Sort and Quicksort)

    Recently I systematicall review some sorting algorithms, including insertion sort, bubble sort, merg ...

  4. 1306. Sorting Algorithm 2016 12 30

    1306. Sorting Algorithm Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One of the f ...

  5. HihoCoder - 1781: Another Bubble Sort (冒泡排序&逆序对)

    Sample Input 3 9 8 7 5 1 9 2 6 4 3 1 2 3 4 5 6 7 8 9 9 8 7 5 1 9 2 6 4 3 1 2 5 4 3 6 7 8 9 9 8 7 5 1 ...

  6. 「SP25784」BUBBLESORT - Bubble Sort 解题报告

    SP25784 BUBBLESORT - Bubble Sort 题目描述 One of the simplest sorting algorithms, the Bubble Sort, can b ...

  7. Bubble Sort (5775)

    Bubble Sort Problem Description   P is a permutation of the integers from 1 to N(index starting from ...

  8. HDU 5775 Bubble Sort(冒泡排序)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  9. 中南大学第一届长沙地区程序设计邀请赛 New Sorting Algorithm

    1352: New Sorting Algorithm Time Limit: 1 Sec  Memory Limit: 128 MB Description We are trying to use ...

随机推荐

  1. PeopleSoft translate value 排序

    这个function 可以对record.field 的dropdownlist 排序,也可以把描述前边加个数字.但是有时候用户不接受.所以调用这个方法是比较好的选择. Function Order_ ...

  2. scanf函数的返回值

    #include <stdio.h> int main() { ]; ]); printf("%d\n", n); ; } 此刻注意scanf函数里面的格式限定,该代码 ...

  3. HttpClient 知识点

    1. httpClient 默认超时时间是 60秒 2.httpClient 是模拟表单提交,所以服务端接口要用HttpServletRequest request 接收  例如: request.g ...

  4. 【论文速读】Fangfang Wang_CVPR2018_Geometry-Aware Scene Text Detection With Instance Transformation Network

    Han Hu--[ICCV2017]WordSup_Exploiting Word Annotations for Character based Text Detection 作者和代码 caffe ...

  5. Tarjan求LCA

    LCA问题算是一类比较经典的树上的问题 做法比较多样 比如说暴力啊,倍增啊等等 今天在这里给大家讲一下tarjan算法! tarjan求LCA是一种稳定高速的算法 时间复杂度能做到预处理O(n + m ...

  6. P3974 [TJOI2015]组合数学

    题目描述 为了提高智商,ZJY开始学习组合数学.某一天她解决了这样一个问题:给一个网格图,其中某些格子有财宝.每次从左上角出发,只能往右或下走.问至少要走几次才可能把财宝全捡完. 但是她还不知足,想到 ...

  7. ftp 上传和下载

    ftp 下载 #!/bin/bash #auth liwei #date DATE=$(date -d today +%Y%m%d) #data files path SRCDIR=/home/web ...

  8. redis知识点汇总

    1. redis是什么 2. 为什么用redis 3. redis 数据结构 4. redis中的对象类型 5. redis都能做什么?怎么实现的的? 6. redis使用过程中需要注意什么 7. 数 ...

  9. 融云通信云发力教育行业 助在线教育"风口"继续腾云

    4 月 16 日,2019 年AI 在线教育大会在北京站圆满落幕,会上云集超过500位资深教育从业者.200 家机构,共同就 AI 教育落地.在线教育应用经验等主题开展深入探讨.云通信领域的领导企业融 ...

  10. 利用 html js判断 客户端是否安装了某个app 安装了就打开 否则跳转到gp

    三种方式 方式一:简单的进行打开app,延时操作若未打开直接跳gp function isInstalled(){ var urlFrag = 'somepars'; var the_href = ' ...