Created
June 2, 2018 09:31
-
-
Save sdelvalle57/f5f65a31150ea9321f081630b416ed99 to your computer and use it in GitHub Desktop.
Sort array in solidity, could be easily used to sort any array of integers too
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract ArraySort { | |
function sort_array(bytes memory arr) private pure returns (bytes) { | |
uint256 l = arr.length; | |
for(uint i = 0; i < l; i++) { | |
for(uint j = i+1; j < l ;j++) { | |
if(arr[i] > arr[j]) { | |
bytes1 temp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = temp; | |
} | |
} | |
} | |
return arr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment