pragma solidity ^0.4.18; contract SimpleStore { uint[] private a = new uint[](10); function getA() public view returns(uint[]) { return a; } function setLen(uint _len) public { require(_len < 32); a.length = _len; } function _getRandomHash() private view returns (bytes32) { return keccak256(now); } function _bytes32ToUintArray(bytes32 b) private pure returns(uint[32] memory ret){ for(uint i=0; i<32; i++){ ret[i] = uint(b[i]); } } function init() public { uint[32] memory b = _bytes32ToUintArray(_getRandomHash()); for(uint i=0; i<a.length; i++){ a[i] = b[i]; } } function _calcCloneArray(uint[] _a) private pure returns(uint[]) { uint aLen = _a.length; uint[] memory b = new uint[](aLen); for(uint i=0; i<aLen; i++){ b[i] = _a[i]; } return b; } function doQuicksort() public { uint[] memory b = _calcCloneArray(a); _quicksort(b); a = b; } function _quicksort(uint[] _a) private pure { uint left = 0; uint right = _a.length - 1; _quicksort_core(_a, left, right); } function _quicksort_core(uint[] _a, uint _left, uint _right) private 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 _getPivot(uint _a, uint _b, uint _c) private pure returns(uint) { if(_a < _b){ if(_b < _c){ return _b; }else{ return _a < _c ? _a : _c; } }else{ if(_a < _c){ return _a; }else{ return _b < _c ? _b : _c; } } } function _swap(uint[] _a, uint _l, uint _r) private pure { uint t = _a[_l]; _a[_l] = _a[_r]; _a[_r] = t; } }
0.4.18