算法题目-冒泡排序
2017-06-12 20:52
183 查看
冒泡排序,是一种经典的排序算法,
冒泡排序的最差、平均时间复杂度都为O(n^2),
空间复杂度为O(1),
它是一种稳定的排序算法。
输出结果:
冒泡排序的最差、平均时间复杂度都为O(n^2),
空间复杂度为O(1),
它是一种稳定的排序算法。
package Website; public class sort { public static void main(String[] args) { int[] arr={1,5,3,2,7,8,9,4,6}; System.out.print("排序前:"); sort.output(arr); sort.BubbleSort(arr); System.out.println(); System.out.print("排序后:"); sort.output(arr); } public static void BubbleSort(int[] a){ for(int i=0;i<a.length-1;i++){ for(int j=0;j<a.length-1-i;j++){ if(a[j]>a[j+1]){ int temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } } public static void output(int[] a){ for(int i=0;i<a.length;i++){ System.out.print(a[i]+" "); } } }
输出结果:
相关文章推荐
- PHP算法面试题目
- 第16周 项目1-验证算法(冒泡排序)
- 经典算法回顾:冒泡排序(又称交换排序)
- [学习笔记]排序算法之冒泡排序
- 傻瓜学算法系列之排序——1.冒泡排序
- 算法第二天--冒泡排序
- acm之贪心算法题目2
- python算法实践3-冒泡排序
- 基础迷宫问题-------------(图的BFS 题目取自算法竞赛入门)
- 算法题目-记hulu失败的实习面试
- 每天一种算法 - 冒泡排序
- Java中的经典算法之冒泡排序(Bubble Sort)
- 蓝桥杯 ADV-162 算法提高 题目1 最大最小值
- 白话经典算法系列之一 冒泡排序的三种实现
- 算法题目----数字反转
- [算法练习] 斐波那契数列 [题目转自飞燕之家]
- C#算法之“冒泡排序”
- LeetCode算法题目:Subsets AND Subsets II
- java 算法之冒泡排序
- 算法题目--Min Cost Climbing Stairs