[Question]
  [
**Locked**. This question and its answers are [locked](/help/locked-posts) because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
 
 
**Note: This question was severely edited since I first posted it here. The rules were moved to [here](https://codegolf.stackexchange.com/tags/code-trolling/info), read them before posting any answer to understand the purpose of this. This was the first question created in the [code-trolling](/questions/tagged/code-trolling "show questions tagged 'code-trolling'") category.**
Imagine a lazy user on Stack Overflow asks this question:
> 
> I need a program where the user inputs an array of doubles and the program outputs the array sorted. Could you please give the code?
> 
> 
> 
How could you create a piece of code that will troll this user? Create a piece of code that will appear useful to an inexperienced programmer but is utterly useless in practice.
The winner is the most upvoted answer, except if the answer is somehow not eligible (for eligibility requirements, check the tag wiki description of [code-trolling](/questions/tagged/code-trolling "show questions tagged 'code-trolling'")). If the previously most upvoted answer is beaten in the future in the number of upvotes after being accepted, the new best answer is accepted and the previous one is unaccepted. In the case of a tie, I will choose the winner at will among the tied ones or just wait a bit more.
Answers that have no code are not eligible. They might be fun and get some upvotes, but they won't be accepted.
Rules can be found at [tag description](https://codegolf.stackexchange.com/tags/code-trolling/info).
Note: This is a [code-trolling](/questions/tagged/code-trolling "show questions tagged 'code-trolling'") question. Please do not take the question and/or answers seriously. More information [here](https://codegolf.stackexchange.com/tags/code-trolling/info).
  
[Answer]
Here it is in java. It is utter cheating, unacceptable and unfixable because it creates a MySQL database, insert the number there, do a select with an ORDER BY clause and outputs the numbers given by MySQL. In fact, it is MySQL who is doing the sorting, not the program.
```
package sorter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
public class SortingAlgorithm {
    private static final String CREATE_DB = "CREATE DATABASE sorting";
    private static final String DROP_DB = "DROP DATABASE sorting";
    private static final String CREATE_TABLE = "CREATE TABLE sorting.sorting ( num double not null )";
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        List<Double> doubles = new ArrayList<>(50);
        String typed;
        do {
            typed = JOptionPane.showInputDialog(null, "Type a double:");
            if (typed != null) doubles.add(Double.parseDouble(typed));
        } while (typed != null);
        List<Double> sorted = new ArrayList<>(50);
        try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "root")) {
            try (PreparedStatement ps = con.prepareStatement(CREATE_DB)) {
                ps.executeUpdate();
            }
            try (PreparedStatement ps = con.prepareStatement(CREATE_TABLE)) {
                ps.executeUpdate();
            }
            for (Double d : doubles) {
                try (PreparedStatement ps = con.prepareStatement("INSERT INTO sorting.sorting (num) VALUES (" + d + ")")) {
                    ps.executeUpdate();
                }
            }
            try (
                    PreparedStatement ps = con.prepareStatement("SELECT * FROM sorting.sorting ORDER BY num");
                    ResultSet rs = ps.executeQuery())
            {
                while (rs.next()) {
                    sorted.add(rs.getDouble("num"));
                }
            }
            try (PreparedStatement ps = con.prepareStatement(DROP_DB)) {
                ps.executeUpdate();
            }
        }
        JOptionPane.showMessageDialog(null, "The array sorted is: " + sorted);
    }
}
```
[Answer]
Sometimes the community here doesn't like to help with homework. That's why you are getting so many joke answers. But I like to help. Here is a complete solution in 'C' (since I assume you want to learn "programming", not "scripting" with Java or Ruby). I've included many tips that I wish I had known when I was first learning
```
#include <stdio.h>
//Always use meaningful names for types
typedef unsigned char boolean;
#define True 't'
#define FALSE (!True)
//this is a really neat trick for swapping values efficiently
void swap(long* a,long *b) { *a=*a^*b;*b=*b^*a;*a=*a^*b; }
//Here's a readability improvement
#define until(condition) while(!(condition))
int main(int n, char*args[]){
  double *d;
  int i;
  char input[5];  //should be long enough for most doubles.
  boolean sorted = FALSE;
  //In C, you need to specify the array size beforehand, so ask
  printf("Please enter the length of the array\n");
  gets(input);
  //scan the input string and convert to a value
  sscanf(input,"%s",&input[0]);
  n=(long)atol(input);
  //allocate space, make sure you get the order of arguments right.
  d = calloc(sizeof(double),n); 
  //Get and sort the array
  until (sorted) {
     for (i=0;i<n;i++) {
        //It's important to always ask nicely
        printf("Please enter the %d%s array item\n",i,i==1?"st":"th");
        scanf("%lf",d+i);
     }
     //do a compare and exchange sort:
     sorted = !sorted;  //not sorted
     //check all the items
     printf("%d %d\n",i,n);
     for (i=1;i<n;i++) {
        //compare
        if (d[i]<d[i-1]) {
          //exchange 
          swap(d+i,d+i-1);
          sorted = FALSE;
        }
     }
     //show results
     printf("The array is%ssorted\n",sorted?" ":" not "); }
  //use the --> "downto operator" for counting downto 0. 
  for (;n-->0;) printf("%lf\n",*d++);
  }
```
[Answer]
# C# - There's no kill like overkill
First of all, dear GiMmEtHaCoDeZ, let's try to break down your task:
1. Read the numbers
2. Sort them
3. Output the sorted numbers.
As "Divide and conquer" is very important strategy when working with software problems, lets tackle them one at a time
# 1. Reading
Another important issue in software is versatility. Since it's not specified how the user will input the numbers, that can happen via the console, via a file, via a web service, etc. Maybe even some method that we can't think of at the moment. So, it's important that our solution will be able to accommodate various types of input. The easiest way to achieve that will be to extract the important part to an interface, let's say
```
public interface IDoubleArrayReader
{
  IEnumerable<double> GetDoubles();
  DoubleArrayReaderType Type {get;}
}
```
where `DoubleArrayReaderType` is an enumeration given with
```
public enum DoubleArrayReaderType
{
  Console,
  File,
  Database,
  Internet,
  Cloud,
  MockService
}
```
It's also important to make the software testable from the ground up, so an implementation of the interface will be
```
public class MockServiceDoubleArrayReader : IDoubleArrayReader
{
    IEnumerable<double> IDoubleArrayReader.GetDoubles()
    {
      Random r = new Random();  
      for(int i =0; i<=10; i++)
      {
        yield return r.NextDouble();
      }
    }
    DoubleArrayReaderType IDoubleArrayReader.Type 
    {
      get
      {
        return DoubleArrayReaderType.MockService;
      }
    }
}
```
Next, the logical question is how we will know to load the appropriate `IDoubleArrayReader` into the code. That's easy as long as we use a simple factory:
```
public static class DoubleArrayInputOutputFactory
{
  private static Dictionary<DoubleArrayReaderType, IDoubleArrayReader> readers;
  static DoubleArrayInputOutputFactory()
  {
      readers = new Dictionary<DoubleArrayReaderType, IDoubleArrayReader>();
      foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
      {
        try
        {
          var instance = Activator.CreateInstance(type);
          if (instance is IDoubleArrayReader)
          {
            readers.Add((instance as IDoubleArrayReader).Type, 
                        (instance as IDoubleArrayReader));
          }
        }
        catch
        {
          continue;
        }
      }
  }
  public static IDoubleArrayReader CreateDoubleArrayReader(DoubleArrayReaderType type)
  {
    return readers[type];
  }
}
```
Note that, we use reflection to load all active readers, so any future extensions will be automatically available
Now, in the main body of out code we just do:
```
IDoubleArrayReader reader = DoubleArrayInputOutputFactory
                           .CreateDoubleArrayReader(DoubleArrayReaderType.MockService);
var doubles = reader.GetDoubles();
```
# 2. Processing (sorting)
Now we need to process, i.e. sort the numbers we have acquired. Note that the steps are completely independent of each other, so to the sorting subsystem, it does not matter how the numbers were inputed. Additionally, the sorting behavior is also something that is subject to change, e.g. we might need to input a more efficient sorting algorithm in place. So, naturally, we'll extract the requested processing behaviour in an interface:
```
public interface IDoubleArrayProcessor
{
  IEnumerable<double> ProcessDoubles(IEnumerable<double> input);
  DoubleArrayProcessorType Type {get;}
}
public enum DoubleArrayProcessorType
{
  Sorter,
  Doubler,
  Tripler,
  Quadrupler,
  Squarer
}
```
And the sorting behaviour will just implement the interface:
```
public class SorterDoubleArrayProcessor : IDoubleArrayProcessor
{
    IEnumerable<double> IDoubleArrayProcessor.ProcessDoubles(IEnumerable<double> input)
    {
      var output = input.ToArray();
      Array.Sort(output);
      return output;
    }
    DoubleArrayProcessorType IDoubleArrayProcessor.Type 
    {
      get
      {
        return DoubleArrayProcessorType.Sorter;
      }
    }
}
```
Of course, we will need a factory to load and manage the processing instances.
```
public static class DoubleArrayProcessorFactory
{
  private static Dictionary<DoubleArrayProcessorType, IDoubleArrayProcessor> processors;
  static DoubleArrayProcessorFactory()
  {
      processors = new Dictionary<DoubleArrayProcessorType, IDoubleArrayProcessor>();
      foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
      {
        try
        {
          var instance = Activator.CreateInstance(type);
          if (instance is IDoubleArrayProcessor)
          {
            processors.Add((instance as IDoubleArrayProcessor).Type, (instance as IDoubleArrayProcessor));
          }
        }
        catch
        {
          continue;
        }
      }
  }
  public static IDoubleArrayProcessor CreateDoubleArrayProcessor(DoubleArrayProcessorType type)
  {
    return processors[type];
  }
}
```
# 3. Writing the output
Nothing much to say here, as this is a process that mirror the input. In fact, we could combine the reading and writing factories into a single `DoubleArrayInputOutputFactory`, like this:
```
public interface IDoubleArrayWriter
{
  void WriteDoublesArray(IEnumerable<double> doubles);
  DoubleArrayWriterType Type {get;}
}
public enum DoubleArrayWriterType
{
  Console,
  File,
  Internet,
  Cloud,
  MockService,
  Database
}
public class ConsoleDoubleArrayWriter : IDoubleArrayWriter
{
    void IDoubleArrayWriter.WriteDoublesArray(IEnumerable<double> doubles)
    {
      foreach(double @double in doubles)
      {
        Console.WriteLine(@double);
      }
    }
    DoubleArrayWriterType IDoubleArrayWriter.Type 
    {
      get
      {
        return DoubleArrayWriterType.Console;
      }
    }
}
public static class DoubleArrayInputOutputFactory
{
  private static Dictionary<DoubleArrayReaderType, IDoubleArrayReader> readers;
  private static Dictionary<DoubleArrayWriterType, IDoubleArrayWriter> writers;
  static DoubleArrayInputOutputFactory()
  {
      readers = new Dictionary<DoubleArrayReaderType, IDoubleArrayReader>();
      writers = new Dictionary<DoubleArrayWriterType, IDoubleArrayWriter>();
      foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
      {
        try
        {
          var instance = Activator.CreateInstance(type);
          if (instance is IDoubleArrayReader)
          {
            readers.Add((instance as IDoubleArrayReader).Type, (instance as IDoubleArrayReader));
          }
        }
        catch
        {
          continue;
        }
      }
      foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
      {
        try
        {
          var instance = Activator.CreateInstance(type);
          if (instance is IDoubleArrayWriter)
          {
            writers.Add((instance as IDoubleArrayWriter).Type, (instance as IDoubleArrayWriter));
          }
        }
        catch
        {
          continue;
        }
      }
  }
  public static IDoubleArrayReader CreateDoubleArrayReader(DoubleArrayReaderType type)
  {
    return readers[type];
  }
  public static IDoubleArrayWriter CreateDoubleArrayWriter(DoubleArrayWriterType type)
  {
    return writers[type];
  }
}
```
# Putting it all together
Finally, our main program will just use all this awesomeness we have already built, so the code will just be:
```
var doubles = reader.GetDoubles();
doubles = processor.ProcessDoubles(doubles);
writer.WriteDoublesArray(doubles);
```
where, e.g. we could define `reader`, `writer` and `processor` using
```
IDoubleArrayReader reader = DoubleArrayInputOutputFactory.CreateDoubleArrayReader(DoubleArrayReaderType.MockService);
IDoubleArrayProcessor processor = DoubleArrayProcessorFactory.CreateDoubleArrayProcessor(DoubleArrayProcessorType.Sorter);
IDoubleArrayWriter writer = DoubleArrayInputOutputFactory.CreateDoubleArrayWriter(DoubleArrayWriterType.Console);
```
[Answer]
Even more literal interpretation:
```
echo " aaehrrty"
```
that is, "the array" sorted.
[Answer]
# Perl
Out of all of the things I've done for CodeGolf.SE, this probably took the most time, at least a few hours.
```
$_[0]=eval<>;
for(0..$#{$_[0]}**2){
 @_[$#_+1]=[\(@{$_[$#_]}),$#{$_[$#_]}+1];
 for(1..$#{$_[$#_]}-$#_){
  if(eval('${'x$#_.'@{$_[$#_]}[$_-1]'.'}'x$#_)>eval('${'x$#_.'@{$_[$#_]}[$_]'.'}'x$#_)){
   ${$_[$#_]}[$#{$_[$#_]}]=$_;
  }
 }
 (${$_[$#_]}[${$_[$#_]}[$#{$_[$#_]}]-1],${$_[$#_]}[${$_[$#_]}[$#{$_[$#_]}]])=(${$_[$#_]}[${$_[$#_]}[$#{$_[$#_]}]],${$_[$#_]}[${$_[$#_]}[$#{$_[$#_]}]-1]);
}
for(0..~~@{$_[0]}){
 $\.=eval('${'x$#_.'${$_[$#_]}[$_-1]'.'}'x$#_).','
}
$\=~s/,*$//;$\=~s/^,*//;$\="[$\]";
print;
```
Input is of the form `[2,4,5,7,7,3]` and output is of the form `[2,3,4,5,7,7]`.
~~I don't have time to explain now... be back later.~~
Anyways, there is something called an anonymous array in Perl. It is an array, but it has no name. What we do know, however, is a reference (memory location) that points to it. A series of numbers in square brackets creates an anonymous array, and it returns a reference to it.
This answer is built off of a series of anonymous arrays, the references to which are stored in `@_`. The input is turned into an anonymous array. We then create other anonymous arrays, each element of which is a reference to an element in the previous array. Instead of sorting the elements in the array, we sort the pointers to the elements in that array. Also, we create a new array for each step (and more) in the sort operation.
[Answer]
## Python
Gives the user a sorted array by removing all elements not in sorted order from the input array.
```
import sys
sorted = []
for number in map(float, sys.stdin.read().split()):
    if not sorted or number >= sorted[-1]:
         sorted.append(number)
print sorted 
```
The algorithm goes through the list only adding each element if it won't make the list unsorted. Thus the output is a sorted list, just not one that's contains all the elements of the original list. If the op just checks if the list is in sorted order he may not notice that the output is missing values.
[Answer]
# Bash, 54 characters
A lot of answers using slow inefficient languages like C and Python... let's speed things up a bit by offering a solution in the mother of all scripting languages: Bash.
I know what you're thinking - Bash can't even handle floating point arithmetic, so how is it going to sort, right? Well, behold, my implementation of the mighty SleepSort algorithm:
```
#!/bin/bash
for i in $@; do echo -n $(sleep $i)$i' '& done
echo "Leveraging the power of your $(grep -c ^processor /proc/cpuinfo) cores to \
sort optimally by spawning $(jobs -l | wc -l) concurrent sorting threads..."
wait
echo -e "\nThe array sorted."
```
The program is provided with input as commandline arguments. Sample run:
```
> ./sleepsort.sh 7 1 4 3 2.752 6.9 0.01 0.02
Leveraging the power of your 4 cores to optimally by spawning 8 concurrent sorting threads...
0.01 0.02 1 2.752 3 4 6.9 7
The array sorted.
```
This also has the advantage of perhaps being the shortest of all working algorithms presented here. That's right - **one mighty line of bash**, using only bash builtins and not calling any external binaries (that is, if you don't count the purely optional verbose output). Unlike the bogosorts, its runtime is deterministic.
Tip: An effective optimisation is to divide the input numbers by a factor before sorting. Implementation is left up to the reader.
## Edit:
Shortened 54-char golf version with less pretty-printing:
```
#!/bin/sh
for i in $@;do echo $(sleep $i)$i&done;wait
```
[Answer]
JavaScript has a built-in `sort()` function, you can use it like this:
```
var numbers = [6, 2.7, 8];
numbers.sort();
// => [2.7, 6, 8]
```
...oh, totally forgot to mention, it sorts in lexicographic order, i.e. `10 < 9` and `9 < -100`. Probably that's what you expect anyway.
[Answer]
## (jPL) jQuery Programming Language
You **must** use jQuery for that. A simple solution to this problem is the following one:
```
function jSort() {
    var a = 0.0; // position 1
    var b = 0.0; // position 2
    var c = 0.0; // position 3
    var arr = [];
    var nArr = [];
    // don't forget to validate our array!
    if (window.prompt("You must only type double values. Type 1 if you accept the terms.") != 1) {
        alert("You can't do that.");
        return;
    }
    for (var i = 0; i < 3; i++) {
        if (i == 0) {
            var a = window.prompt("Type a double value");
            arr.push(a);
        }
        if (i == 1) {
            var b = window.prompt("Type a double value");
            arr.push(b);
        }
        if (i == 2) {
            var c = window.prompt("Type a double value");
            arr.push(c);
        }
    }
    // Now the tricky part
    var b1 = false;
    var b2 = false;
    var b3 = false;
    for (var i = 0 ; i < 3; i++) {
        // check if the variable value is the same value of the same variable which now is inside the array
        if (i == 0) {
            if (a == arr[i]) {
                b1 = true;
            }
        }
        if (i == 1) {
            if (b == arr[i]) {
                b2 = true;
            }
        }
        if (i == 2) {
            if (c == arr[i]) {
                b3 = true;
            }
        }
    }
    if (b1 == true && b2 == true && b3 == true) {
        if (arr[0] > arr[1]) {
            if (arr[0] > arr[2]) {
                nArr.push(arr[0]);
            } else {
                nArr.push(arr[2]);
            }
        }
        if (arr[1] > arr[0]) {
            if (arr[1] > arr[2]) {
                nArr.push(arr[1]);
            }
            else {
                nArr.push(arr[2]);
            }
        }
        if (arr[2] > arr[0]) {
            if (arr[2] > arr[1]) {
                nArr.push(arr[2]);
            } else {
                nArr.push(arr[1]);
            }
        }
        console.log(arr.sort(function (a, b) { return a - b }));
        alert(arr.sort(function (a, b) { return a - b }));
    }
}
jSort();
```
[Answer]
# Ruby
```
print "Input an array of doubles: "
gets
puts "the array sorted."
```
Fairly self-explanatory.
Or require the input to actually be "an array of doubles":
```
print "Input an array of doubles: "
g = gets until /an array of doubles\n/
puts "the array sorted."
```
Not using `gets.chomp` for extra evilness. Also using regex after trailing until, which is something I didn't even know you could do (thanks Jan Dvorak) to confuse OP even more! 
[Answer]
# C
This solution combines the conciseness and OS-level access provided by C with the powerful, reusable software components in GNU/Linux:
```
#include <stdlib.h>
main(int argc, char **argv)
{
    system("echo Enter numbers one per line, ending with ctrl-D; sort -g");
}
```
[Answer]
**Python3.3**
> 
> Sure, here's the *most simple* Python program that can sort an array
>  given as a list literal on stdin:
> 
> 
> 
> ```
> collections = __import__(dir(object.__subclasses__()[7])[1][4:-3] + chr(116))
> 
> URL = ('https://www.google.com/search?client=ubuntu&channel=fs&q=dante+alighieri'
>       '%27s+divina+commedia&ie=utf-8&oe=utf-8#channel=fs&q=__++divina+commedia+'
>       'dante+alighieri+inferno+__').translate(
>           dict.fromkeys(map(ord, '+-.:,;bcdefghjklopqrstuvwxyz/&=#?%')))[30:]
> SECRET_KEY = URL[2:10][::-1][3:-1]
> DATA = '{}{}{}'.format(URL[:2], SECRET_KEY[:2] + SECRET_KEY[:-3:-1], URL[-2:])
> 
> 
> 
> if getattr(DATA, dir(list)[7])(__name__):
>     pieces = 'literally - evil'.split(' - ')
>     r = getattr(collections, 
>                 '_'.join([pieces[0][:-2],
>                           pieces[1].translate({ord('j')-1: 'a'})])
>                 )((getattr(globals()['__{}__'.format('buildings'.translate(
>                         {100:'t', 103:None}))], 'in' r"put"))
>                   ())
>     tuple((lambda lst:
>            (yield from map(list,
>                            map(lambda k: (yield from k), 
>                                ((lambda i: (yield from map(lambda t:
>                                              (lst.append(lst[i]) or
>                                               lst.__setitem__(i, lst[t]) or
>                                               lst.__setitem__(t, lst.pop())),
>                                               (j for j in range(i)
>                                                 if (lambda: lst[i] < lst[j])())
>                                               ))
>                                 )(è) for è in range(
>                                                 getattr(lst,
>                                                         dir(lst)[19])()))))
>           )
>         )(r))
>     print(r)
> 
> ```
> 
> Unfortunately it works only in python3.3+ since it uses the `yield
>  from` expression. The code should be quite self-explanatory, so you
>  shouldn't have any problems when handing it in to your professor.
> 
> 
> 
---
The trolling is in providing a *perfectly working* solution that does exactly what the OP intended, but in a way that is:
* impossible to understand (by a beginner)
* impossible to handle in to the teacher because:
	+ the OP can't understand it
	+ even if he could the teacher wouldn't have time to decipher in order to understand it
* *scary* for a naive newbie which might think that programming is too hard for him
In summary this answer would greatly increase the frustration of the student mocking their requests with perfectly valid answers from a certain point of view.
---
(Do not read if you consider a challenge understanding the code above)
I must add that the trolling is also increased by the fact that the sorting algorithm implemented is actually
> 
>  **bubble-sort!**... which could surely be implemented in a way that even
>  the OP could understand. It's not an obscure algorithm per se, just
>  a good code-obfuscation of something that the OP could otherwise
>  understand perfectly.
> 
> 
> 
[Answer]
# Ruby, evil Bogosort! (Bonus: bogosort by user input)
```
print "Input array of doubles, separated by commas: "
arr = gets.split(",")
arr.shuffle! until arr.each_cons(2).all? {|x| x[0] < x[1]}
puts arr * ","
```
The "evil" twists: 
* runs really really really really really really really slowly, of course
* uses string comparison, so 10 is less than 2. Can be fixed easily with `.map &:to_f` appended to the second line, but OP might not know that
* not using `chomp` so the last number has a mysterious newline at the end
* not using `strip` so there is mysterious whitespace around numbers if input with spacing around commas (ex. The space in `1.5, 2`)
Or, how about **bogosorting by *user input*?!** >:D
```
print "Input array of doubles, separated by commas: "
arr = gets.split(",")
arr.shuffle! until arr.each_cons(2).all? {|x|
    print "Is #{x[0]} less than #{x[1]}? (y/n) "
    gets =~ /y/
}
puts arr * ","
```
[Answer]
## C - Slow, hard to use, unacceptable coding style
The sorting algorithm itself is known as slowsort, and has a best case complexity (simplexity) of around *n^(log n/2)*. The algorithm has been published by Andrei Broder and Jorge Stolfi in their great paper ["Pessimal Algorithms and Simplexity Analysis"](http://ivanych.net/doc/PessimalAlgorithmsAndSimplexityAnalysis.pdf) which I highly recommend for good laughs AND food for thought.
```
void sort(double* arr, int n, int i, int j)
{
        if(i < j) {
                int m = (i+j)/2;
                sort(arr, n, i  , m);
                sort(arr, n, m+1, n);
                if(arr[m] > arr[j]) {
                        double t = arr[j];
                        arr[j] = arr[m];
                        arr[m] = t;
                }
                sort(arr, n, i, j-1);
        }
}
```
However the sorting itself is useless, so we need a way for user to input the data they want to sort. Parsing doubles is pain, so why not input them byte by byte.
```
const unsigned MAX_ELEMS = 100;
int main()
{
        int i=0, j=0, len;
        char a[MAX_ELEMS*8];
        double* arr = (double*) a;
        short isNull=1;
        while(1) {
                a[i++] = getchar();
                if(i%8 == 0) {
                        if(isNull)
                                break;
                        isNull = 1;
                }
                else if(a[i-1] != 0)
                        isNull = 0;
        }
        len=i/8 - 1;
        sort(arr, len-1, 0, len-1);
        for(i = 0; i < len; i++)
        {
                printf("%f ", arr[i]);
        }
}
```
To prove that it works:
```
 $ gcc -g trollsort.c -o trollsort
trollsort.c: In function ‘main’:
trollsort.c:43:3: warning: incompatible implicit declaration of built-in function ‘printf’
 $ echo -en "\0\0\0\0\0\xe4\x94\x40\0\0\0\0\0\0\xf0\x3f\0\0\0\0\0\0\x45\x40\0\0\0\0\0\0\0\0" | ./trollsort
1.000000 42.000000 1337.000000
```
In the end we have:
* The slowest deterministic sorting algorithm I'm aware of
* Silent hard coded limits on list length
* Absolutely horrible input, I could also make output similar but I think it's funnier this way.
	+ Consider: You will need to know which endianess your machine is to use the program.
	+ Also you cannot input 0 (-0 is ok)
* Pointer arithmetics and pretty much no concern for types as pointers are casted whichever way
[Answer]
# COBOL
Sure! ["Even a monkey can do this!"](https://codegolf.stackexchange.com/a/16245/10612)
Here is a [simple COBOL program](http://theamericanprogrammer.com/programming/10-sortex1.shtml) that will sort the input for you. Read the comments to see exactly how trivial and extensible it is. The real benefits of this are that it is tried and true mechanism, it does not rely on new and relatively untested languages like Java and anything web-based or from Microsoft. It compiles really effectively, and procedures like this are used by the most successful financial companies in the Fortune500 and other industry leaders. This code has been reviewed by many experts and is recognized as being an excellent mechanism for sorting.
```
000100 IDENTIFICATION DIVISION.
000200* Cobol sort. Consistent with COBOL 390
000300* does not use sections; does not use go to
000400* uses sort procedures
000500* does a sort with some minimal input validation
000600* since everything is done in an orderly way,
000700* you can easily add code of your own to this program
000800 PROGRAM-ID. 'SORTEX1'.
000900 ENVIRONMENT DIVISION.
001000 CONFIGURATION SECTION.
001100 INPUT-OUTPUT SECTION.
001200 FILE-CONTROL.
001300*    INPUT FILE UNSORTED
001400     SELECT UNSORTED-FILE ASSIGN UNSORTED.
001500*    The work file for the sort utility
001600*    you need the select and an sd but do not need jcl for it
001700     SELECT SORT-WORK      ASSIGN      SORTWORK.
001800*    output file normally a disk/tape file
001900*    for this program, send it to the printer
002000     SELECT SORTED-FILE ASSIGN SORTED.
002100*
002200 DATA DIVISION.
002300 FILE SECTION.
002400*
002500 FD  UNSORTED-FILE
002600     RECORDING MODE IS F
002900     RECORD CONTAINS  80 CHARACTERS.
003000
003100 01  UNSORTED-RECORD.
003200     05  WS-UR-ACCT-NO        PIC X(5).
003300     05  FILLER               PIC X(5).
003400     05  WS-UR-AMOUNT         PIC 9(5).
003500     05  WS-UR-CUST-NAME      PIC X(10).
003600     05  FILLER               PIC X(5).
003700     05  WS-UR-TRANS-CODE     PIC X(1).
003800     05  FILLER               PIC X(49).
003900
004000  SD  SORT-WORK
004400      RECORD CONTAINS  80 CHARACTERS.
004500*
004600 01  SORT-WORK-RECORD.
004700*    You need a definition and picture for
004800*    the field that is sorted on (sort key)
004900     05  SW-ACCT-NO    PIC X(05).
005000*    YOU NEED A FILLER TO COMPLETE THE DEFINITION
005100     05  FILLER        PIC X(75).
005200*
005300 FD  SORTED-FILE
005400     RECORDING MODE IS F
005700     RECORD CONTAINS  80 CHARACTERS.
005800*
005900 01  SORTED-RECORD.
006000     05  WS-SR-ACCT-NO        PIC X(05).
006100     05  FILLER               PIC X(05).
006200     05  WS-SR-AMOUNT         PIC 9(05).
006300     05  WS-SR-CUST-NAME      PIC X(10).
006400     05  FILLER               PIC X(55).
006500
006600 WORKING-STORAGE SECTION.
006700 01  SWITCHES.
006800     05  UNSORTED-FILE-AT-END      PIC X   VALUE 'N'.
006900     05  SORT-WORK-AT-END          PIC X   VALUE 'N'.
007000     05  valid-sw                  PIC X   VALUE 'N'.
007100
007200 01  COUNTERS.
007300      05 RELEASED-COUNTER PIC S9(7)
007400                PACKED-DECIMAL VALUE +0.
007500      05 REJECT-COUNTER   PIC S9(7)
007600                PACKED-DECIMAL VALUE +0.
007700
007800 PROCEDURE DIVISION.
007900     PERFORM INITIALIZATION
008000*    Compare this logic to that of the simple program
008100*    notice how the sort verb replaces the
008200*    perform main until end of file etc
008300     SORT SORT-work ASCENDING KEY SW-ACCT-NO
008400         INPUT PROCEDURE SORT-INPUT
008500         OUTPUT PROCEDURE SORT-OUTPUT
008600     PERFORM      TERMINATION
008700     GOBACK.
008800
008900 INITIALIZATION.
009000*    Do what you normally do in initialization
009100*    open the regular input file (not the sort work file)
009200*    and other files needed
009300*    (you could open them in the sort input procedure, too)
009400     OPEN INPUT UNSORTED-FILE
009500          output SORTED-FILE
009600*    READ THE FIRST RECORD ON THE REGULAR INPUT FILE
009700     PERFORM READ-IT.
009800*    Whatever else you do in initialization
009900*    headers, initialize counters, etc
010000
010100 TERMINATION.
010200*    Do what you normally do in termination
010300*    print out total lines
010400*    close the files you opened
010500*    display totals
010600     CLOSE UNSORTED-FILE
010700           SORTED-FILE.
010800
010900 READ-IT.
011000     READ UNSORTED-FILE
011100     AT END MOVE 'Y' TO UNSORTED-FILE-AT-END
011200     END-READ.
011300
011400 SORT-INPUT.
011500*    This is the 'sort input procedure'
011600*    when control passes thru the last statement in it
011700*    the input phase of the sort is finished
011800*    and actual sorting takes place
011900     PERFORM SORT-INPUT-PROCESS-ALL
012000        UNTIL UNSORTED-FILE-AT-END = 'Y'.
012100
012200  SORT-INPUT-PROCESS-ALL.
012300*  This is the point when you have each unsorted input record
012400*  in your hands
012500*  many programs do some validation or selection here
012600*  to determine which records are actually given to the sort util
012700*  we will do some simple validation here
012800     MOVE 'Y' TO VALID-SW
012900     PERFORM SORT-INPUT-VALIDATE
013000     IF VALID-SW = 'Y'
013100     THEN
013200**       Give the unsorted input record to the sort utility
013300         RELEASE SORT-work-RECord FROM unsorted-RECORD
013400         ADD 1 TO RELEASED-COUNTER
013500     ELSE
013600**       Here, you have decided not to give the unsorted input
013700**       record to the sort utility
013800         ADD 1 TO REJECT-COUNTER
013900     END-IF
014000     PERFORM READ-IT.
014100
014200 SORT-INPUT-VALIDATE.
014300*    Check the regular input record for validity.
014400*    if it is not suitable for sorting, set the valid sw
014500*    other validation criteria would apply for other files
014600     IF WS-UR-ACCT-NO IS equal to spaces
014700        THEN MOVE 'N' TO VALID-SW
014800     END-IF.
014900
015000 SORT-OUTPUT.
015100*    This is the 'sort output procedure'
015200*    when control passes thru the last statement in it
015300*    the output phase of the sort is finished
015400*    you have seen (returned) the last sorted record
015500*    and the sort utility is finished
015600     PERFORM RETURN-IT
015700     PERFORM SORT-OUTPUT-PROCESS-ALL
015800         UNTIL SORT-WORK-AT-END = 'Y'.
015900
016000 RETURN-IT.
016100*    Gets each sorted record from the sort utility
016200*    return is logically like a read
016300      RETURN SORT-work
016400         AT END MOVE 'Y' TO SORT-work-AT-END
016500      END-RETURN.
016600
016700 SORT-OUTPUT-PROCESS-ALL.
016800      PERFORM SORT-OUTPUT-PROCESSING
016900      PERFORM RETURN-IT.
017100 SORT-OUTPUT-PROCESSING.
017200* Here you do the things you do in a
017300* regular program's main processing routine
017400* add totals, compute things
017500* write detail records, print lines, etc
017600* you could put control break check here
017700* this program just and writes the record out to "sorted file"
017900     MOVE SORT-WORK-RECORD TO SORTED-RECORD
018100     WRITE SORTED-RECORD.
```
[Answer]
OP never said HOW to sort them... or what his definition of doubles is. Assuming datatype `double` but interpreting it as *duplicates*. Using JavaScript here.
```
var arr = [4, 6, 7, 4, 5, 9, 11, 7],
    flag = 1,
    result = [];
while( arr.length ) {
  for( var i = 0, index = 0; i < arr.length; ++i ) {
    if( arr[i] * flag < arr[index] * flag ) {
      console.log(arr[i], arr[index]);
      index = i;
    }
  }
  arr.splice(index, 1);
  flag = -flag;
}
```
Result: alternating order `[4, 11, 4, 9, 5, 7, 6, 7]`
[Answer]
# PHP
Here is a full implementation with error handling. It is the fastest for any `array of doubles`.
```
<?php
  function arraySorter($arr) {
      foreach ($arr as $el) {
          if ($el != 'double') {
              throw new Exception('Unexpected Error: Invalid array!');
          }
      }
      return $arr;
  }
  
  $arrayOfDoubles = Array('double', 'double', 'double', 'double', 'double');
  var_dump(arraySorter($arrayOfDoubles));
?>
```
[Answer]
[solution by punctilious misdirection]
Please read the relevant standard, IEC 60559:1989
*Specification for binary floating point arithmetic for microprocessor systems*, which you can purchase [here](http://shop.bsigroup.com/ProductDetail/?pid=000000000000218955). In the footnote to §5.10 *Details of totalOrder predicate*, it is noted that:
> 
> totalOrder does not impose a total ordering on all encodings in a format. In particular, it does not distinguish among different encodings of the same floating-point representation, as when one or both encodings are non-canonical.
> 
> 
> 
Thus we see that it is impossible to write code to sort doubles. It is a trick question. Ha, ha, very clever! Please tell your professor I am enjoying his course very much.
[edit: nothing requires me *not* to assume that the problem demands a total order]
[Answer]
```
do
{
}
while(next_permutation(begin(ar), end(ar)));
```
Next permutation in C++ works by returning true when the array is sorted and false otherwise (after it permutes). So you are supposed to sort the array and then use it in a do-while as above (so it will make a full circle back to the sorted array).
[Answer]
**An evil JavaScript:**
OP, I don't want to give you everything so I'll let you figure out how to get input from the user on your own (hint: use `prompt`). 
Once you have that, here is a function you can pass your array into to sort it. You just need to provide the array, the lowest value in the array, and an increment:
```
var sortDoubles = function (unsortedArray, minimumVal, increment) {
    var sortedArray = [];
    while (unsortedArray.length != sortedArray.length) {
        var index = unsortedArray.indexOf(minimumVal);
        if (index != -1) {
            sortedArray.push(unsortedArray[index]);
        }
        minimumVal += increment;
    }
    return sortedArray;
};
```
[Here is a fiddle to see it in action with the example user input [1.5, -3.5, 12, 10, -19.5].](http://jsfiddle.net/briguy37/qMZG5/)
---
Note: Aside from being poor-performing, complex, and unextensible for the problem at hand, this will be especially frustrating if the OP doesn't know about floating point math. For example, if the user input is `[8.1, 5, -.8, 2.3, 5.6, 17.9]` and the OP chooses the straightforward values (i.e. `minimumVal=-.8` and `increment=.1`), the program will run forever. On a related note, I am currently the proud owner of 2 non-functioning browser tabs due to this very issue :)
Note II: I felt disgusting even writing the above code.
Note III: **MWA HAHAHAHA!**
[Answer]
### Genetic algorithm/Monte Carlo method for the sorting problem in JAVA
The sorting problem is known to computing science for a long time and many good solutions have been found. In recent years there have been great advances in biocomputing and looking at how biology solves problems has shown to be of great help in solving hard problems. This sorting algorithm takes the best of these ideas to use them to solve the sorting problem. The idea is pretty simple. You start with an unordered array and find out how sorted this is already. You give it a score of its "sortedness" and then permute the array with a random component - just like in biology where it is not clear how the kids will look like even if you know all about the parents! This is the genetic algorithm part. You create the offspring of that array so to say. Then you see if the offspring is better sorted than the parent (aka survival of the fittest!). If this is the case you go on with this new array as starting point to build the next permutation and so forth until the array is fully sorted. The cool thing about this approach is that it takes shorter, if the array is already a bit sorted from the start!
```
package testing;
import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
import org.joda.time.DateTime;
import org.joda.time.Interval;
public class MonteCarloSort {
    private static final Random RANDOM  = new Random();
    public static void main(String[] args) {
        List doubleList = new java.awt.List();
        //  prompt the user to enter numbers
        System.out.print("Enter a number or hit return to start sorting them!");
        //  open up standard input
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = null;
        //  read the numbers from the command-line; need to use try/catch !!!
        do{
            try {
                input = br.readLine();
            } catch (IOException ioe) {
                System.out.println("IO error trying to read a number!");
                System.exit(1);
            }
                try {
                    double d = Double.parseDouble(input);
                    doubleList.add(input);
                } catch (NumberFormatException e) {
                    if (!input.equals("")) System.out.println("Only numbers are allowed.");
                }
        } while (!input.equals(""));
        printCurrentListAndStuff(doubleList);
        while (isAscSorted(doubleList) < doubleList.getItemCount()){
            List newlist = createPermutation(doubleList);
            //genetic algorithm approach!
            if (isAscSorted(doubleList) <= isAscSorted(newlist)){
                //the new list is better, so we use it as starting point for the next iteration!
                doubleList = newlist;
                printCurrentListAndStuff(doubleList);
            }
        }
        System.out.println("done!");
    }
    private static void printCurrentListAndStuff(List doubleList){
        System.out.print("array sortedness is now " + isAscSorted(doubleList) + "(max = "+doubleList.getItemCount()+"): ");
        printList(doubleList);
        System.out.print("\n"); 
    }
    private static void printList(List doubleList){
        for (int i = 0; i < doubleList.getItemCount(); i++){
            String doubleVal = doubleList.getItem(i);
            System.out.print((i>0?", ":"") +doubleVal);
        }   
    }
    private static List createPermutation(List doubleList){
        int sortedness = isAscSorted(doubleList);
        if (sortedness == doubleList.getItemCount()) return doubleList;
        //we take the first non fitting item and exchange it by random
        int swapWith = RANDOM.nextInt(doubleList.getItemCount());
        //it makes no sense to swap with itself, so we exclude this
        while (swapWith == sortedness){
            swapWith = RANDOM.nextInt(doubleList.getItemCount());
        }
        List newList = new List();
        for (int i = 0; i < doubleList.getItemCount(); i++){
            if ( i == sortedness){
                newList.add(doubleList.getItem(swapWith));  
            }
            else if ( i == swapWith){
                newList.add(doubleList.getItem(sortedness));    
            }
            else{
                newList.add(doubleList.getItem(i));
            }
        }
        return newList;
    }
    /**
     * A clever method to get the "degree of sortedness" form a given array. the
     * bigger the number the more sorted it is. The given list is fully sorted if
     * the return value is the length of the list!
     * 
     * @param doubleList
     * @return a number
     */
    private static int isAscSorted(List doubleList){
        double current = Double.NEGATIVE_INFINITY;
        for (int i = 0; i < doubleList.getItemCount(); i++){
            String doubleVal = doubleList.getItem(i);
            if (Double.parseDouble(doubleVal) >= current){
                current = Double.parseDouble(doubleVal);
            }
            else{
                return i;
            }
        }
        return doubleList.getItemCount();
    }
}
```
## Extras
* Misuse of java.awt.List
* inconsistent and bad variable naming
* completely bullshit blah blah about biocomputing
* inventive and inconsistent language in the explanation
* monte carlo is plainly the wrong tool for straight forward deterministic problems
* unneeded imports
* probably more goodies...
[Answer]
[Here is an actual answer](https://stackoverflow.com/a/8938285/1937270) that I like for Java:
> 
> Add the Line before println and your array gets sorted
> 
> 
> 
> ```
> Arrays.sort( array );
> 
> ```
> 
> 
No explanation, [confuses the OP](https://stackoverflow.com/questions/8938235/java-sort-an-array#comment11186695_8938285), but works and will get upvotes from more experienced programmers.
---
Another [similar answer](https://stackoverflow.com/a/8938268/1937270):
> 
> Take a look at [Arrays.sort()](http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#sort%28int%5B%5D%29)
> 
> 
> 
Indirectly telling the OP to do his own research while giving him a vague correct answer. Without further research, the [OP is still confused](https://stackoverflow.com/questions/8938235/java-sort-an-array#comment11186702_8938268). I also like that the link points to older documentation.
[Answer]
## Python
```
a = map(float, raw_input().split())
print sorted(a, key=lambda x: int(x * 10**3) % 10 + int(x * 10**5) % 10)
```
Sorts the array (list) by the sum of the 3rd and 5th decimal places.
[Answer]
Here, feast your eyes:
```
<?php
if (isset($_POST["doubleArray"]) === true) {
    $doubleValues = explode(":", $_POST["doubleArray"]);
    if (is_numeric($_POST["smallestDouble"]))
    {
        $sorted = $_POST["sorted"] . ":" . $doubleValues[$_POST["smallestDouble"]];
        unset($doubleValues[$_POST["smallestDouble"]]);
        $doubleValues = array_values($doubleValues);        
    }
    if (count($doubleValues) > 0) {
        $i = 0;
        foreach ($doubleValues as $value) {
            echo $i . " : " . $value . "<br />";
            $i++;
        }
        echo "Type the index of the smallest double value in the list: ";
    } else {
        echo "Sorted values" . $sorted;
    }
}else {
       echo "Enter double values separated by a colon (:)";
}
?>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<?php
if (!isset($doubleValues)) {
    echo '<input type="text" name="doubleArray" /><br>';
} else {
    echo '<input type="hidden" name="doubleArray" value="' .
    implode(":", $doubleValues) .
    '" ><input type="text" name="smallestDouble" /><br>'.
    '<input type="hidden" name="sorted" value="' . $sorted . '" >';
}
?>
    <input type="submit" value="Submit">
</form>
```
This piece of code displays the array and asks the user to enter the smallest double of the array. It then adds the number to the list of sorted numbers, removes the double from the array and display the remaining array numbers.
**\* Misinterpreting:** Weak point, but the OP is not exactly expecting the program to ask the user to help sorting.
**\* Cheating:** the user is the one doing the actual sorting.
**\* Performance:** Every number of the array requires a server roundtrip, and it requires the user to find the smallest number manually. Performance can't get much worse.
**\* Unacceptable:** I think I got that covered. And good luck on reusing it. Worst comes to worst, the user could get rid of 90% of the code and loop through repetitively to find the smallest values and removing them each time, which would give him one of the least efficient sorting algorithms.
**\* Creative and evil:** you tell me.
[Answer]
# Javascript Intelligent Design Sort
```
function sort(array){
    console.log("Someone more intelligent than you has already sorted this optimally. Your puny brain cannot comprehend it");
    return array;//I do believe that this is the fastest sorting algorithm there is!
}
```
[Answer]
**C++** 
This works... eventually.
Here's my sorting algorithm:
```
template <typename Iterator>
void sort (Iterator first, Iterator last)
{
    while (std::is_sorted (first, last) == false) {
        std::shuffle (first, last, std::random_device()) ;
    }
}
```
Here's the full program: 
```
#include <algorithm>
#include <iostream>
#include <random>
#include <string>
#include <sstream>
#include <vector>
namespace professional 
{
    template <typename Iterator>
    void sort (Iterator first, Iterator last) ;
} // end of namespace professional
std::vector <double> get_doubles () ;
int main (void)
{
    std::vector <double> vecVals = get_doubles () ;
    professional::sort (std::begin (vecVals), std::end (vecVals)) ;
    for (const double d : vecVals) {
        std::cout << d << " " ;
    }
    std::cout << std::endl ;
    return 0 ;
}
template <typename Iterator>
void professional::sort (Iterator first, Iterator last)
{
    while (std::is_sorted (first, last) == false) {
        std::shuffle (first, last, std::random_device()) ;
    }
}
std::vector <double> get_doubles ()
{
    std::cout << "Please enter some space delimited doubles." << std::endl ;
    std::vector <double> vecVals ;
    std::string strLine ;
    std::getline (std::cin, strLine) ;
    std::stringstream ss (strLine) ;
    while (1) {
        double d = 0 ;
        ss >> d ;
        if (ss.bad () == false && ss.fail () == false) {
            vecVals.push_back (d) ;
        }
        else {
            break ;
        }
    }
    return vecVals ;
}
```
[Answer]
# Python – req. #1
This code will sort the doubles in lexicographical order rather than increasing numerical order, by creating a prefix tree of digits and then iterating through them recursively.
```
class trie_node:
    def __init__(self):    
        self.chn = {}
        self.instances = 0
        for char in "0123456789.-+e":
            self.chn[char] = None
    def insert_number(self, number):
        if(number == ""):
            self.instances += 1
        else:
            self.chn[number[0]] = trie_node()
            self.chn[number[0]].insert_number(number[1:])
def get_sorted_array(node, number):
    array_to_return = [number] * node.instances
    for char in "0123456789.-+e":
        if node.chn[char] != None:
            array_to_return += get_sorted_array(node.chn[char], number + char)
    return array_to_return
def pcg_sort(arr):
    root = trie_node()
    for element in arr:
        root.insert_number(str(element))
    sarr = get_sorted_array(root, "")
    fsarr = []
    for element in sarr:
        fsarr.append(float(element))
    return fsarr
input_array = []
while True:
    number = raw_input("Enter a double (/ to end): ")
    if(number == "/"):
        print pcg_sort(input_array)
        break
    else:
        try:
            number = float(number)
            input_array.append(number)
        except ValueError:
            pass
```
It works in `n log n` time, and is in fact a smart way to keep a sorted list otherwise, but unfortunately for the OP, it does completely the wrong thing.
[Answer]
Sorts the array of doubles. In Java:
```
public String sort(double[] input){
String s = "";
for(Double d:input){
    s+=Long.toBinaryString(Double.doubleToRawLongBits(d));
}
char[] chars=s.toCharArray();
Arrays.sort(chars);
s="";
for(char c:chars){
    s+=c;
}
return s;}
```
For instance:
`[0.0, 1.5, 123]`
goes from the unsorted binary representation of
`011111111111000000000000000000000000000000000000000000000000000100000001011110110000000000000000000000000000000000000000000000`
to the elegantly sorted
`000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111`
[Answer]
> 
> I need a program where the user inputs an array of doubles and the program outputs the array sorted. Could you please give the code?
> 
> 
> 
Edit per @kealist, I guess it is better if commented to make the divide seem plausible. In [Rebol](http://en.wikipedia.org/wiki/Rebol)...
```
doubled-list: load ask "Input list of doubles: "
;-- The list is of doubles, so we have to undouble them before sorting
;-- Use MAP-EACH to create a new list with each element divided by two
undoubled-list: map-each num doubled-list [num / 2] 
;-- Note: We could also have sorted before we undoubled the numbers
print sort undoubled-list
```
Playing off the idea that they don't actually know what a double is, and might believe a list of doubles were just a bunch of numbers multiplied by two.
[Answer]
Deliberately misunderstanding the question:
Using a recursive approach:
```
def recsort(array):
    "Recursive sort"
    if array:
        for j, i in enumerate(array):
            for l1 in recsort(array[:j]):
                for l2 in recsort(array[j+1:]):
                    yield i + l1 + l2
                    yield i + l2 + l1
    else:
        yield ''
for p in recsort(raw_input("Array:")):
    print p
```
The sorted array is guaranteed to be outputed at some point, for any type of data in the array, even any kind of sorting order, and even any kind of separator for the input, which makes this approach extremely flexible. Its main drawback is that it is a bit slow for large arrays, but you can solve that easily with multithreading.
]