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 #34

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
- Please use 3.x python only.

## Current List of Sorting Algos:
- [Quick Sort](https://github.com/Zircoz/Sorting-Algorithms-in-Python/blob/master/QuickSort.py)
- [Selection Sort](https://github.com/Zircoz/Sorting-Algorithms-in-Python/blob/master/Selection_Sort.py)
- [Insertion Sort](https://github.com/Zircoz/Sorting-Algorithms-in-Python/blob/master/insertion_sort.py)
- [Merge Sort](https://github.com/Zircoz/Sorting-Algorithms-in-Python/blob/master/merge_sort.py)
- [Bubble Sort](https://github.com/Zircoz/Sorting-Algorithms-in-Python/blob/master/bubbleSort.py)
- [Counting Sort](https://github.com/Zircoz/Sorting-Algorithms-in-Python/blob/master/counting_sort.py)
- [Heap Sort](https://github.com/blackeye735/Sorting-Algorithms-in-Python/blob/master/Heapsort.py)
- [Bucket Sort](https://github.com/Zircoz/Sorting-Algorithms-in-Python/blob/master/bucket_sort.py)
- [Tree Sort](https://github.com/Zircoz/Sorting-Algorithms-in-Python/blob/master/tree_sort.py)
- [Quick Sort](QuickSort.py)
- [Selection Sort](Selection_Sort.py)
- [Insertion Sort](insertion_sort.py)
- [Merge Sort](merge_sort.py)
- [Bubble Sort](BubbleSort/bubbleSort.py)
- [Counting Sort](counting_sort.py)
- [Heap Sort](HeapSort/Heapsort.py)
- [Bucket Sort](BucketSort/bucket_sort.py)
- [Tree Sort](tree_sort.py)
- [Sleep Sort](SleepSort/sleepSort.py)


## Proposed List of Sorting Algos:
Expand Down
10 changes: 10 additions & 0 deletions SleepSort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Sleep sort is a sorting algorithm where
* a thread are created for every element in the unsorted list
* put the thread on sleep for a certian amount of time i.e., if the element is 2, make the thread sleep for 2 units.
* print the element or store the elment.

So basically, larger the value longer sleep period for the thread, smaller the value less sleep period for the thread
which leads the program to sort the given array.

Source
[StackExchange](https://softwareengineering.stackexchange.com/a/106356)
10 changes: 10 additions & 0 deletions SleepSort/sleepSort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Sleep sort is a sorting algorithm where
* a thread are created for every element in the unsorted list
* put the thread on sleep for a certian amount of time i.e., if the element is 2, make the thread sleep for 2 units.
* print the element or store the elment.

So basically, larger the value longer sleep period for the thread, smaller the value less sleep period for the thread
which leads the program to sort the given array.

Source
[StackExchange](https://softwareengineering.stackexchange.com/a/106356)
11 changes: 11 additions & 0 deletions SleepSort/sleepSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import threading
import time

def sort(num):
time.sleep(num)
print(num, end = ' ')

to_sort = [9,8,7,6,5,4,3,2,1,0]
for x in to_sort:
t = threading.Thread(target=sort, args=(x,))
t.start()