标签:冒泡排序 面试
一、基础版~冒泡排序
/* * @author opxin * @version 1.0 * 冒泡算法 * */ public class BubbleSort { public static void main(String[] args) { int[] number = { 36,12,78,51,93,18,88,29,64,45}; int temp = 0; for (int i = 0; i < number.length; i++) { for (int j = 0; j < number.length - 1 - i; j++) { if (number[j] > number[j + 1]) { temp = number[j]; number[j] = number[j + 1]; number[j + 1] = temp; } } } for (int i = 0; i < number.length; i++) { System.out.print(number[i] + " "); } } }
输出结果:12 18 29 36 45 51 64 78 88 93
二、优化版~冒泡排序(挖坑代填)
本文出自 “opxin” 博客,谢绝转载!
标签:冒泡排序 面试
原文地址:http://8351498.blog.51cto.com/8341498/1435316