博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BubbleSort
阅读量:4109 次
发布时间:2019-05-25

本文共 952 字,大约阅读时间需要 3 分钟。

package com.citi.byteman.test.arithmatic;public class Bubble {	public void bubbleSort(int[] array) {		for (int j = 1; j < array.length; j++) {			for (int i = 0; i < array.length - j; i++) {				if (array[i] > array[i + 1]) {					int temp = array[i + 1];					array[i + 1] = array[i];					array[i] = temp;				}			}		}	}	public void printArray(int[] array) {		for (int i = 0; i < array.length; i++) {			System.out.print(array[i] + "\t");		}		System.out.println("");	}	public static void main(String[] args) {		Bubble bubble = new Bubble();		int[] array = { 49, 38, 65, 97, 76, 13, 27, 49, 78, 34, 12, 64, 5, 4,				62, 99, 98, 54, 56, 17, 18, 23, 34, 15, 35, 25, 53, 51 };		// int[] array = { 49, 38, 65, 97, 76, 13, 27, 78, 34, 12, 64, 5, 4, 62,		// 99, 98, 54, 56, 17, 18, 23, 15, 35, 25, 53, 51 };		System.out.println("before sort:");		bubble.printArray(array);		bubble.bubbleSort(array);		System.out.println("after sort:");		bubble.printArray(array);	}}

转载地址:http://fnlsi.baihongyu.com/

你可能感兴趣的文章
从山寨Spring中学习Spring IOC原理-自动装配注解
查看>>
实例区别BeanFactory和FactoryBean
查看>>
Spring后置处理器BeanPostProcessor的应用
查看>>
Spring框架的ImportSelector到底可以干嘛
查看>>
Mysql中下划线问题
查看>>
Linux命令 之 cat less more tail head
查看>>
Cortex-M3开发经验(二):确定发生HardFault的地方
查看>>
Cortex-M3开发经验(三):在HardFault中打印栈信息
查看>>
Qt原理分析(一):Qt中的消息处理
查看>>
Qt原理分析(二):Qt中自定义槽函数
查看>>
Qt原理分析(三):Qt中自定义信号
查看>>
Qt原理分析(四):信号与槽的连接方式
查看>>
Qt原理分析(五):Qt中信号与槽的对应关系
查看>>
Qt原理分析(六):Qt中的事件处理
查看>>
2、Python 文件基本操作
查看>>
3、Python 对异常的操作
查看>>
4、Python函数
查看>>
5、python闭包
查看>>
6、python 装饰器的使用
查看>>
7、python类的定义和使用
查看>>