# Submission 72319100...

Challenge Integer sorting 0xabcdef0db461f2f... 2018-19-28 993608
``````/**
* This file is part of the 1st Solidity Gas Golfing Contest.
*
*/

pragma solidity 0.4.24;

contract Sort {

/**
* @dev Sorts a list of integers in ascending order.
*
* The input list may be of any length.
*
* @param input The list of integers to sort.
* @return The sorted list.
*/
function sort(uint[] input)
public
pure
returns(uint[]) {
if (input.length < 2) {
return input;
}

uint t = input.length - 1;
if (t == 1) {
if (input[0] > input[1]) {
(input[0], input[1]) = (input[1], input[0]);
}
return input;
}

uint c = t / 2;
if (input[0] < input[c]) {
if (input[c] < input[t]) {
} else {
if (input[0] < input[t]) {
(input[c], input[t]) = (input[t], input[c]);
} else {
(input[0], input[c], input[t]) = (input[t], input[0], input[c]);
}
}
} else {
if (input[c] < input[t]) {
if (input[0] < input[t]) {
(input[0], input[c]) = (input[c], input[0]);
} else {
(input[0], input[c], input[t]) = (input[c], input[t], input[0]);
}
} else {
(input[0], input[t]) = (input[t], input[0]);
}
}
if (t == 2) {
return input;
}

quickSortAsc(input, 0, t, input[c]);
return input;
}

function quickSortAsc(uint[] input, uint head, uint tail, uint mval)
internal
pure
{
uint t = tail;
while (h <= t) {
while (input[h] < mval) {
h++;
}
while (mval < input[t]) {
t--;
}
if (h <= t) {
(input[h], input[t]) = (input[t], input[h]);
h++;
if (t > 0) {
t--;
}
}
}