Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ed855d6

Browse files
Merge pull request #140 from gauravdarbhanga/patch-2
Comments on CountingSort.java
2 parents c4dab39 + 38d06ee commit ed855d6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

‎src/com/jwetherell/algorithms/sorts/CountingSort.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /