Skip to content

Commit 3d357b6

Browse files
committed
Review comments
1 parent 79551af commit 3d357b6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/main/java/com/thealgorithms/sorts/SleepSort.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ public static List<Integer> sleepSort(List<Integer> array) {
3333
List<Integer> sortedList = Collections.synchronizedList(new ArrayList<>());
3434
List<Thread> threads = new ArrayList<>();
3535

36+
// Validate that all numbers are non-negative before starting any threads
3637
for (int number : array) {
3738
if (number < 0) {
3839
throw new IllegalArgumentException("All numbers must be non-negative. Found: " + number);
3940
}
41+
}
42+
43+
for (final int number : array) {
4044
Thread thread = new Thread(() -> {
4145
try {
4246
Thread.sleep(number); // Sleep for 'number' milliseconds

0 commit comments

Comments
 (0)