sorting algorithm
  • Introduction
  • Wikipedia-sorting-algorithm
  • sorting algorithm
  • 历史 History
  • 分类 Classification
    • 稳定性 Stability
  • 算法比较 Comparison of algorithms
  • 流行排序算法 Popular sorting algorithms
    • 简单排序 Simple sorts
      • 插入排序 Insertion sort
      • 选择排序 Selection sort
    • 高效排序 Efficient sorts
      • 合并排序 Merge sort
      • 堆排序 Heapsort
      • 快速排序 Quicksort
    • 冒泡排序与变种 Bubble sort and variants
      • 冒泡排序 Bubble sort
      • 希尔排序 Shellsort
      • 梳排序 Comb sort
    • 分发排序 Distribution sort
      • 计数排序 Counting sort
      • 桶排序 Bucket sort
      • 基数排序 Radix sort
  • 内存使用模式和索引排序 Memory usage patterns and index sorting
  • 相关算法 Related algorithms
  • 另见 See also
  • 参考文献 References
  • 进一步阅读 Further reading
  • 外部链接 External links
Powered by GitBook
On this page
  • Bubble sort冒泡排序
  • principle原理
  • example示例

Was this helpful?

  1. 流行排序算法 Popular sorting algorithms
  2. 冒泡排序与变种 Bubble sort and variants

冒泡排序 Bubble sort

Previous冒泡排序与变种 Bubble sort and variantsNext希尔排序 Shellsort

Last updated 5 years ago

Was this helpful?

Bubble sort冒泡排序

@See @See - BubbleSort

principle原理

依次两两比较,把大数向后置换,最后数在最后,最小数在最前。 每轮排完,下轮排序个数减一。

example示例

public void sort(int[] list) {
        for (int i = list.length - 1; i > 0; i--) {//循环列表长减一次。
            for (int j = 0; j < i; j++) {//从最左向右比较交换
                if (list[j + 1] < list[j]) {
                    swap(list, j, j + 1);
                }
            }
        }
    }
https://en.wikipedia.org/wiki/Bubble_sort
https://github.com/jiek2529/java_algorithm