All pastes #987723 Raw Edit

COMPARABLE SORT

public text v1 · immutable
#987723 ·published 2008-04-16 20:50 UTC
rendered paste body
import java.util.Arrays;
public class Sorting{
	
//	public int compareTo(Object obj){
//		if (this < obj){
//			return  - 1;
//		}
//		if (this == obj){
//			return 0;
//		}
//		if (this.compareTo(obj) > obj){
//			return 1;
//		}
//		return this.compareTo(obj);
//	}
	public void insertSort(Comparable [] cArray){


		for (int i = 0; i < cArray.length; i ++){
			Comparable objOne = cArray[i];
			int j = i - 1;
			
			Comparable objTwo= cArray[j];
			while(objOne.compareTo(objTwo) > 0 && j > 0){
				cArray[j + 1] = cArray[j];
				j --;
				if(j  >= 0){
				objTwo= cArray[j];
				}
			}
			cArray[j + 1] = objOne;
			
			System.out.println(Arrays.toString(cArray));
		}
	}
}