diff --git a/Sorting Algorithms/Java/SleepSort.java b/Sorting Algorithms/Java/SleepSort.java new file mode 100644 index 00000000..4f90e32c --- /dev/null +++ b/Sorting Algorithms/Java/SleepSort.java @@ -0,0 +1,38 @@ +import java.util.ArrayList; +import java.util.concurrent.CountDownLatch; + +public class SleepSort { + //Sleep sort puts each element of an integer array into sleep at the same time + // due to the value differences, the smaller value would "wake up" first hence added to + // the array first and so on. + private static Thread Tread; + + public static void main(String[] args) { + int[] nums = {0,1,2,3,4}; + sleepSort(nums); + } + + public static void sleepSort(int[] nums){ + CountDownLatch completeSignal = new CountDownLatch(nums.length); + ArrayList sortedNums = new ArrayList<>(); + for(int i = 0; i