首页 > 编程语言 > 详细

冒泡排序

时间:2021-05-22 10:43:52      阅读:33      评论:0      收藏:0      [点我收藏+]

图解:
技术分享图片


实例代码:

package compary;


import java.util.Arrays;

public class Main {

public static void main(String[] args) {

int[] a={6,1,3,5,7,4,9};

int[] result=sort(a);

System.out.println(Arrays.toString(result)+",");
}

public static int[] sort(int[] arrays)
{
int temp=0;
boolean fal=false;
for (int i = 0; i <arrays.length-1 ; i++) {

for (int j = 0; j <arrays.length-1-i ; j++) {
if (arrays[j+1]>arrays[j])
{
temp=arrays[j];
arrays[j]=arrays[j+1];
arrays[j+1]=temp;
fal=true;
}
}
if (fal==false)
{
break;
}
}
return arrays;
}
}

冒泡排序

原文:https://www.cnblogs.com/zsy3025/p/14797735.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!