sorting Algorithm implementation in Java