# Submission aca34e48...

Challenge Integer sorting hyszeth.eth 2018-18-16 962041
``````/**
* This file is part of the 1st Solidity Gas Golfing Contest.
*
*
* Author: Greg Hysen (@hysz)
* Date: June, 2018
*/

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 == 0) return input;
quickSort(input, 0, input.length - 1);
return input;
}

function quickSort(
uint[] input,
uint lo,
uint hi
)
internal
pure
{
uint iElem;
uint jElem;
/*
if(hi - lo < 3) {
// If within threshold, run insertion sort instead.
for(i = lo + 1; i <= hi; i++) {
j = i;
for(; j > lo && (iElem=input[j-1]) > (jElem=input[j]); j--) {
(input[j], input[j-1]) = (iElem, jElem);
}
}
return;
}*/
if(hi-lo == 1) {
if((iElem=input[lo]) > (jElem=input[hi])) {
(input[lo], input[hi]) = (jElem, iElem);
}
return;
}

// Pivot
uint pivot = input[uint((hi+lo)/2)];
uint i = lo - 1;
uint j = hi + 1;
while(true) {
while((iElem=input[uint(++i)]) < pivot) {}
while((jElem=input[uint(--j)]) > pivot) {}

if(i >= j) break;
(input[uint(i)], input[uint(j)]) = (jElem, iElem);
}

// Sort
if(lo < j) quickSort(input, lo, j);
j++;
if(j < hi) quickSort(input, j, hi);
}
}

``````