Skip to content

Instantly share code, notes, and snippets.

@sdelvalle57
Created June 2, 2018 09:31
Show Gist options
  • Save sdelvalle57/f5f65a31150ea9321f081630b416ed99 to your computer and use it in GitHub Desktop.
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
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