We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 79551af commit 3d357b6Copy full SHA for 3d357b6
src/main/java/com/thealgorithms/sorts/SleepSort.java
@@ -33,10 +33,14 @@ public static List<Integer> sleepSort(List<Integer> array) {
33
List<Integer> sortedList = Collections.synchronizedList(new ArrayList<>());
34
List<Thread> threads = new ArrayList<>();
35
36
+ // Validate that all numbers are non-negative before starting any threads
37
for (int number : array) {
38
if (number < 0) {
39
throw new IllegalArgumentException("All numbers must be non-negative. Found: " + number);
40
}
41
+ }
42
+
43
+ for (final int number : array) {
44
Thread thread = new Thread(() -> {
45
try {
46
Thread.sleep(number); // Sleep for 'number' milliseconds
0 commit comments