X Tutup
import java.util.*; /* * created by sijunhe on 05/09/2015 * Sorting - Implement two types of sorting algorithms: Merge sort and bubble sort */ public class sort { public static void main(String[] args) { int[] a = {15,8,7,3,9,2,1,6,8,12,5,8,6,22,31,1,0,3}; int[] b = {15,8,7,3,9,2,1,6,8,12,5,8,6,22,31,1,0,3}; mergeSort(a); bubbleSort(b); System.out.println("Test merge sort " + Arrays.toString(a)); System.out.println("Test bubble sort " + Arrays.toString(b)); } public static void mergeSort(int[] input){ int[] buff = new int[input.length]; mergeSort(input,buff,0,input.length-1); } private static void mergeSort(int[] input, int[] buff, int low, int high){ if (low original[j + 1]){ //if earlier element is greater, swap temp = original[j]; original[j] = original[j + 1]; original[j + 1] = temp; } } } } }
X Tutup