Update PigeonholeSort.java
This commit is contained in:
parent
9fe55c82d8
commit
1274140ea3
@ -17,20 +17,12 @@ public class PigeonholeSort {
|
|||||||
public Integer[] sort(Integer[] arr) {
|
public Integer[] sort(Integer[] arr) {
|
||||||
|
|
||||||
// Find maximum and minimum elements in array
|
// Find maximum and minimum elements in array
|
||||||
int min = arr[0];
|
int min = Integer.MAX_VALUE;
|
||||||
int max = arr[0];
|
int max = Integer.MIN_VALUE;
|
||||||
|
|
||||||
for (Integer integer : arr) {
|
for (Integer integer : arr) {
|
||||||
|
min = Math.min(min, integer);
|
||||||
// For minimum value
|
max = Math.max(max, integer);
|
||||||
if (min > integer) {
|
|
||||||
min = integer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For maximum value
|
|
||||||
if (max < integer) {
|
|
||||||
max = integer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Range
|
// Range
|
||||||
|
Loading…
Reference in New Issue
Block a user