Commits

Anonymous committed 086a174

changed the comments

Comments (0)

Files changed (1)

src/KthSmallestElement.java

 import java.util.Random;
 
 /**
- * 2 method to find k-th smallest int in a array
+ * 2 methods to find k-th smallest int in a array
  *
- * @author Absolute Noob
+ * @author AbsoluteNoob
  *
  */
 public class KthSmallestElement {
 	 */
 	private static void insertValueToSortedArray(int[] array,
 			int startIndex, int endIndexAndNewValue) {
-		int unSortedValue = array[endIndexAndNewValue]; // save new
-														// value
+		// save new value
+		int unSortedValue = array[endIndexAndNewValue];
 
 		// comparing all elements in the already sorted region with
 		// new value
 		for (int i = endIndexAndNewValue - 1; i >= 0; i--) {
 			if (array[i] > unSortedValue) {
-				array[i + 1] = array[i]; // shift an element to the
-											// right
-				if (i == 0) // special case when new value is the
-							// smallest value
+				// shift an element to the right
+				array[i + 1] = array[i];
+				// special case when new value is the smallest value
+				if (i == 0)
 					array[i] = unSortedValue;
-			} else { // correct location is found for the new value
+			} else {
+				// correct location is found for the new value
 				array[i + 1] = unSortedValue;
 				break;
 			}