X Tutup
Skip to content

Commit 205aec0

Browse files
committed
Changed the names of the counting sort methods
Added curly braces for the loop
1 parent f564fa4 commit 205aec0

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Sorts/CountingSort.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* @author Podshivalov Nikita (https://github.com/nikitap492)
1515
*
1616
*/
17-
1817
class CountingSort {
1918

2019
/**
@@ -25,7 +24,7 @@ class CountingSort {
2524
* Sorts the list in increasing order
2625
* The method uses list elements as keys in the frequency map
2726
**/
28-
public static <T extends Comparable<T>> List<T> CS(List<T> list) {
27+
public static <T extends Comparable<T>> List<T> countingSort(List<T> list) {
2928

3029
Map<T, Integer> frequency = new TreeMap<>();
3130
// The final output array
@@ -36,8 +35,9 @@ public static <T extends Comparable<T>> List<T> CS(List<T> list) {
3635

3736
// Filling the sortedArray
3837
for(Map.Entry<T, Integer> element : frequency.entrySet()) {
39-
for(int j=0; j<element.getValue(); j++)
38+
for(int j=0; j<element.getValue(); j++){
4039
sortedArray.add(element.getKey());
40+
}
4141
}
4242

4343
return sortedArray;
@@ -46,12 +46,12 @@ public static <T extends Comparable<T>> List<T> CS(List<T> list) {
4646

4747
/**
4848
* Stream Counting Sort
49-
* The same as method {@link CountingSort#CS(List)} but this method uses stream API
49+
* The same as method {@link CountingSort#countingSort(List)} but this method uses stream API
5050
*
5151
* @param list The list to be sorted
5252
*
5353
**/
54-
public static <T extends Comparable<T>> List<T> streamCS(List<T> list) {
54+
public static <T extends Comparable<T>> List<T> streamCountingSort(List<T> list) {
5555
return list.stream()
5656
.collect(toMap(k -> k, v -> 1, (v1, v2) -> v1 + v2, TreeMap::new))
5757
.entrySet()
@@ -70,9 +70,9 @@ public static void main(String[] args) {
7070

7171
// Output => 1 1 4 6 9 9 12 23 23 54 78 231
7272
System.out.println("After Sorting:");
73-
printList(CS(unsortedInts));
73+
printList(countingSort(unsortedInts));
7474
System.out.println("After Sorting By Streams:");
75-
printList(streamCS(unsortedInts));
75+
printList(streamCountingSort(unsortedInts));
7676

7777
System.out.println("\n------------------------------\n");
7878

@@ -84,10 +84,10 @@ public static void main(String[] args) {
8484

8585
//Output => a a b c c d e f g
8686
System.out.println("After Sorting:");
87-
printList(CS(unsortedStrings));
87+
printList(countingSort(unsortedStrings));
8888

8989
System.out.println("After Sorting By Streams:");
90-
printList(streamCS(unsortedStrings));
90+
printList(streamCountingSort(unsortedStrings));
9191

9292
}
9393

0 commit comments

Comments
 (0)
X Tutup