码迷,mamicode.com
首页 > 编程语言 > 详细

冒泡排序

时间:2018-03-17 12:11:43      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:使用   sort   isp   bubble   冒泡排序   length   system   main   程序   

冒泡排序

//使用Java中的数组程序进行泡泡排序
public class BubbleSort {
	static int[] a = {6,4,5,2,3,1};
	public static void main(String[] args) {
		sort(a);
		display();
	}
	public static void sort(int[] a){
		int length = a.length;
		for(int i=0;i<length-1;i++){
			for(int j=0;j<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 display(){
		for(int i:a){
			System.out.print(i+" ");
		}
	}
}

  

冒泡排序

标签:使用   sort   isp   bubble   冒泡排序   length   system   main   程序   

原文地址:https://www.cnblogs.com/hglibin/p/8588222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!