Java examples for Data Structure:Sort
Bubble Sort int array
//package com.java2s; public class Main { public static void BubbleSort(int[] array) { int size = array.length; for (int i = 0; i < size - 1; i++) { boolean hasSwap = false; for (int j = i + 1; j < size; j++) { if (array[j] < array[i]) { // swap int temp = array[i]; array[i] = array[j]; array[j] = temp;/*from www .j ava 2 s .c om*/ hasSwap = true; } } if (!hasSwap) { break; } } } }