WTF-Solidity icon indicating copy to clipboard operation
WTF-Solidity copied to clipboard

第10章插入排序一个直观的实现

Open chenyan opened this issue 3 years ago • 1 comments

contract Sort {
    function sort(uint[] memory array) public pure returns(uint[] memory) {
      uint i = 1;
      while (i < array.length) {
        uint j = i;
        while (j > 0 && array[j-1] > array[j]) {
          (array[j-1], array[j]) = (array[j], array[j-1]);
          j--; 
        }
        i++;
     }
     return(array); 
    } 
}

chenyan avatar Sep 13 '22 09:09 chenyan

Nice, (a, b) = (b, a) 很棒,不用搞个临时变量。

AmazingAng avatar Sep 22 '22 08:09 AmazingAng