pragma solidity ^0.4.18; contract SimpleStore { uint[] ary; function swap(uint[] a, uint l, uint r) private pure { uint t = a[l]; a[l] = a[r]; a[r] = t; } function getBubbleSortedAry(uint[] a) public pure returns(uint[]) { uint len = a.length; uint i; uint j; for(i=0; i<len-1; i++){ for(j=i+1; j<len; j++){ if(a[j] < a[i]){ swap(a,i,j); } } } return a; } function test_getBubbleSortedAry() public view returns(uint[]){ return getBubbleSortedAry(ary); } function bubbleSortIndirect2() public { uint[] memory clone = getBubbleSortedAry(ary); for(uint i=0; i<ary.length; i++){ ary[i] = clone[i]; } } function bubbleSortIndirect() public { uint len = ary.length; uint i; uint j; uint[] memory clone = new uint[](len); for(i=0; i<len; i++){ clone[i] = ary[i]; } for(i=0; i<len-1; i++){ for(j=i+1; j<len; j++){ if(clone[j]<clone[i]){ swap(clone, i, j); } } } for(i=0; i<len; i++){ ary[i] = clone[i]; } } function bubbleSortDirect() public { uint len = ary.length; uint t; for(uint i=0; i<len-1; i++){ for(uint j=i+1; j<len; j++){ if(ary[j] < ary[i]){ t = ary[i]; ary[i] = ary[j]; ary[j] = t; } } } } function getArray() public view returns (uint[]){ return ary; } function setAryRandom5() public { uint length = 5; setAryReverse(length); } function setAryRandom8() public { uint length = 8; setAryReverse(length); } function setAryRandom10() public { uint length = 10; setAryReverse(length); } function setAryReverse(uint length) private { ary = new uint[](length); for(uint i=0; i<length; i++){ ary[i] = length-1-i; } } }
0.4.18