@@ -27,26 +27,26 @@ private CountingSort() { }
2727
2828 public static Integer [] sort (Integer [] unsorted ) {
2929 int maxValue = findMax (unsorted );
30- int [] counts = new int [maxValue + 1 ];
30+ int [] counts = new int [maxValue + 1 ];//counts number of elements
3131 updateCounts (unsorted , counts );
3232 populateCounts (unsorted , counts );
3333 return unsorted ;
3434 }
35- 35+ //finding maximum value in unsorted array
3636 private static int findMax (Integer [] unsorted ) {
37- int max = Integer .MIN_VALUE ;
37+ int max = Integer .MIN_VALUE ;//assume minimum value(-2147483648) of interger is maximum
3838 for (int i : unsorted ) {
3939 if (i > max )
4040 max = i ;
4141 }
4242 return max ;
4343 }
44- 44+ //Incrementing the number of counts in unsorted array
4545 private static void updateCounts (Integer [] unsorted , int [] counts ) {
4646 for (int e : unsorted )
4747 counts [e ]++;
4848 }
49- 49+
5050 private static void populateCounts (Integer [] unsorted , int [] counts ) {
5151 int index = 0 ;
5252 for (int i = 0 ; i < counts .length ; i ++) {
0 commit comments