Skip to content

Instantly share code, notes, and snippets.

@seanavery
Created October 24, 2016 21:20
Show Gist options
  • Save seanavery/816fb589b9e7a1b8e663eaaf0797009f to your computer and use it in GitHub Desktop.
Save seanavery/816fb589b9e7a1b8e663eaaf0797009f to your computer and use it in GitHub Desktop.
sorting algorithm
function submitBid(uint _price, uint _amount) bidInMarket(_price) external returns (bool) {
Bid memory b;
b.price = _price;
b.amount = _amount;
for(uint i = 0; i < Bids.length; i++) {
if(Bids[i].price > _price) {
Bid[] memory tempBids = new Bid[](Bids.length - i);
for(uint j = i; j < Bids.length; j++) {
tempBids[j-i] = Bids[j];
}
Bids[i] = b;
Bids.length = Bids.length + 1;
for(uint k = 0; k < tempBids.length; k++) {
Bids[i+k+1] = tempBids[k];
}
return true;
}
}
Bids.push(b);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment