Draft:Sleepsort
Submission declined on 20 November 2024 by 1AmNobody24 (talk). This submission is not adequately supported by reliable sources. Reliable sources are required so that information can be verified. If you need help with referencing, please see Referencing for beginners and Citing sources.
Where to get help
How to improve a draft
You can also browse Wikipedia:Featured articles and Wikipedia:Good articles to find examples of Wikipedia's best writing on topics similar to your proposed article. Improving your odds of a speedy review To improve your odds of a faster review, tag your draft with relevant WikiProject tags using the button below. This will let reviewers know a new draft has been submitted in their area of interest. For instance, if you wrote about a female astronomer, you would want to add the Biography, Astronomy, and Women scientists tags. Editor resources
|
Sleepsort is a Sorting algorithm that takes an array of numbers, gives each number in said array a thread and puts it to sleep for the duration of the number. Due to major drawbacks, it is not considered a useful algorithm in most circumstances.
Class | Sorting |
---|---|
Data structure | Array |
Worst-case performance | template |
Characteristics
[edit]Advantages
[edit]Sleepsort is relatively easy to code.
Disadvantages
[edit]Sleepsort does not sort negative numbers and simple arrays with large numbers will take a long time.
Examples of sleepsort code
[edit]C#
[edit]using System;
using System.Collections.Generic;
using System.Threading;
class Program
{
int[] input;
int[] output;
static void Routine(int num)
{
Thread.Sleep(num);
for (i = 1, i < output.Length, 1++)
{
if (output[i] == null) output[i] = num;
}
}
static void SleepSort(int[] arr)
{
List<Thread> threads = new List<Thread>();
foreach (int num in arr)
{
Thread thread = new Thread(() => Routine(num));
threads.Add(thread);
thread.Start();
}
foreach (Thread thread in threads)
{
thread.Join();
}
}
static void Main()
{
output = new int[input.Length];
SleepSort(input);
}
}