Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitscript authored Sep 27, 2022
1 parent 49f0bc8 commit b32bc03
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions 15Day-ArraySorting.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;

contract Day3 {
//Create a function sort(array, length of array) . This sort() will take two arguments - a dynamic uint type array and length of the array.
function sort(int256[] memory array, uint256 size)
public
pure
returns (int256[] memory)

{
//The sort() will sort the array elements in ascending order.
for (uint256 step = 0; step < size - 1; ++step) {
int256 swapped = 0;

for (uint256 i = 0; i < size - step - 1; ++i) {
if (array[i] > array[i + 1]) {
int256 temp;
temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;

swapped = 1;
}
}

if (swapped == 0) {
break;
}
}
return array;
}
}

0 comments on commit b32bc03

Please sign in to comment.