分割-ソートのマージ


package divideConquer;

import java.util.Arrays;
/*
 * 		 
 * 		 
 * 		 :[)  0 
 * */
public class MergeSort {
	
	public static void merge(int a[],int low,int high)
	{
		int mid = (low+high)/2;
		int data[] = new int[high-low];
		int i = low,j = mid,k = 0;
		while(i<mid&&j<high)
		{
			if(a[i]<a[j])
				data[k++] = a[i++];
			else
				data[k++] = a[j++];
		}
		while(i<mid) {
			data[k++] = a[i++];
		}
		while(j<high) 
			data[k++] = a[j++];
		for(i =0;i<data.length;i++)//  
			a[i+low] = data[i];//data  0 ,  a   low  
	}
	public static void mergeSort(int data[],int low,int high)
	{
		if(low+1>=high)//  0  , low+1>=high
			return;
		int mid = (low+high)/2;
		mergeSort(data,low,mid);
		mergeSort(data,mid,high);
		merge(data,low,high);
	}
	public static void main(String args[])
	{
		int data []  = {5,2,8,1,7 ,2 ,8 ,5,2,5,2,5};
		//merge(data,2,4);
		mergeSort(data, 0, 12);
		System.out.println(Arrays.toString(data));
	}
}