pragma solidity ^0.4.18; contract SimpleStore { function getRandomHash() public view returns(bytes32) { return keccak256(now); } function getRandomIntArray() public view returns(uint[]) { uint[] memory a = new uint[](32); bytes32 hash = getRandomHash(); for(uint i=0; i<32; i++){ a[i] = uint(hash[i]); } return a; } function getPivot(uint a, uint b, uint c) public pure returns(uint) { if(a>b){ if(b>c){ return b; }else{ return a>c ? c:a; } }else{ if(a>c){ return a; }else{ return b>c ? c:b; } } } function swap(uint[] a, uint l, uint r) public pure { uint t = a[l]; a[l] = a[r]; a[r] = t; } function quicksort(uint[] a) public pure { uint left = 0; uint right = a.length - 1; quicksort_core(a, left, right); } function quicksort_core( uint[] a, uint left, uint right ) public pure { if(right <= left){ return; } uint l = left; uint r = right; uint p = getPivot(a[l], a[l+1], a[r]); while(true){ while(a[l] < p){ l++; } while(p < a[r]){ r--; } if(r<=l){ break; } swap(a, l, r); l++; r--; } quicksort_core(a, left, l-1); quicksort_core(a, r+1, right); } function get() public view returns(uint[]) { uint[] memory a = getRandomIntArray(); quicksort(a); return a; } }
0.4.18