Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.