Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sleep sort #5285

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

aishuarya
Copy link

@aishuarya aishuarya commented Jul 12, 2024

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2024

Codecov Report

Attention: Patch coverage is 80.76923% with 5 lines in your changes missing coverage. Please review.

Project coverage is 40.74%. Comparing base (f1e2606) to head (4e3b94d).
Report is 28 commits behind head on master.

Files Patch % Lines
...c/main/java/com/thealgorithms/sorts/SleepSort.java 80.76% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5285      +/-   ##
============================================
+ Coverage     40.67%   40.74%   +0.06%     
- Complexity     2502     2509       +7     
============================================
  Files           519      520       +1     
  Lines         15447    15473      +26     
  Branches       2949     2953       +4     
============================================
+ Hits           6283     6304      +21     
- Misses         8869     8874       +5     
  Partials        295      295              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aishuarya aishuarya force-pushed the feature/sleepSort branch 8 times, most recently from 5e02a8b to 6e789ad Compare July 12, 2024 08:02
src/main/java/com/thealgorithms/sorts/SleepSort.java Outdated Show resolved Hide resolved
for (int numbers : array) {
Thread thread = new Thread(() -> {
try {
Thread.sleep(numbers); // Sleep for 'num' milliseconds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is a good idea to throw IllegalArgumentException, when any of the entries is negative?

src/main/java/com/thealgorithms/sorts/SleepSort.java Outdated Show resolved Hide resolved
@aishuarya
Copy link
Author

@vil02 Addressed you comments ! Thanks .

Copy link
Member

@vil02 vil02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just some obvious remarks. I will provide more feedback, when I will have a bit more time.

Comment on lines +37 to +39
if (number < 0) {
throw new IllegalArgumentException("All numbers must be non-negative. Found: " + number);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should happen, before starting any of the new threads.

List<Integer> sortedList = Collections.synchronizedList(new ArrayList<>());
List<Thread> threads = new ArrayList<>();

for (int number : array) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (int number : array) {
for (final int number : array) {

@aishuarya
Copy link
Author

@vil02 Addressed you comments .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants