πͺ 2023. 05. 12. Friday_ ν λͺ λ¨ κ³΅μ§! λλ₯! πͺ
β
μλ νμΈμ!π
λͺ¨λ ν¨κ» 4κ°μ λμ νλμ λ©μ§ νλ‘μ νΈλ₯Ό μμ±νλ κ·Έλ κΉμ§ νμ΄ν
ν©μλ€ !πππ
β
* μ΄ κ³³μμλ λΉμΌμ λ°°μ΄ λ΄μ©μ 볡μ΅νλ μ©λλ‘ κΈμ μμ±νλ €κ³ ν©λλ€.
β
* μ€λμ μ리λν°μ 'Sorting' λ΄μ©μ 볡μ΅ν΄λ³΄κ² μ΅λλ€.
β
β
β
function sorting() public {
for(uint i=0;i<numbers.length-1;i++) {
for(uint j=i+1; j<numbers.length ;j++) {
if(numbers[i] < numbers[j]) {
(numbers[i], numbers[j]) = (numbers[j], numbers[i]);
}
}
}
}
function sorting2() public {
for(uint j=1; j<numbers.length;j++) {
for(uint i=0; i<j; i++) {
if(numbers[i] < numbers[j]) {
(numbers[i], numbers[j]) = (numbers[j], numbers[i]);
}
}
}
}
//κ°μ₯ μμμ μλ 4λͺ
μ μ°Ύκ³ μ sortingμ νκ²λ κ²μ΄λ€ ==
contract Sorting{
//μ«μν λ³μ numbers
uint[] numbers;
//numbersμ νΉμ ν κ°μ λ£λ ν¨μ
function push(uint _n) public {
numbers.push(_n);
}
//μ 체 arrayλ₯Ό λ°νλ°λ ν¨μ
function get() public view returns(uint[] memory) {
return numbers;
}
//5μ리μ μλ₯Ό μ λ ¬ν κ²½μ°
//01,02,03,04 - 12,13,14 - 23,24 - 34 μμΌλ‘ λΉκ΅
function sorting() public {
for(uint i=0;i<numbers.length-1;i++) {
for(uint j=i+1; j<numbers.length ;j++) {
if(numbers[i] < numbers[j]) {
(numbers[i], numbers[j]) = (numbers[j], numbers[i]);
}
}
}
}
//λ λλνκ³ ν¨μ¨μ μΈ λ°©λ²!!!
//01 - 02,12 - 03,13,23 - 04,14,24,34 μμΌλ‘ λΉκ΅νκ² λ
function sorting2() public {
for(uint j=1; j<numbers.length;j++) {
for(uint i=0; i<j; i++) {
if(numbers[i] < numbers[j]) {
(numbers[i], numbers[j]) = (numbers[j], numbers[i]);
}
}
}
}
}
β
β
βοΈ Sorting μ€μ΅ μ½λ -(1)
β β βͺοΈ 01,02,03,04 - 12,13,14 - 23,24 - 34 μμΌλ‘ λΉκ΅
β β βͺοΈ address payable owner : λμ λ°μ μ μλ address ν λ³μ ownder μ μΈ
β
βοΈ Sorting μ€μ΅ μ½λ -(1)
β β βͺοΈ 01 - 02,12 - 03,13,23 - 04,14,24,34 μμΌλ‘ λΉκ΅
β β βͺοΈ λ λλνκ³ ν¨μ¨μ μΈ λ°©λ²μ΄λ€ !
β
β
β
β
1. push() μ¬μ©νμ¬ 2,5,7,4,3,6 λ£μ΄λ³΄κΈ°
2. get() μ¬μ©νμ¬ κ²°κ³Ό νμΈ -> 2,5,7,4,3,6
3. sorting() μ¬μ© ν, get()μΌλ‘ κ²°κ³Ό νμΈ -> 7,6,5,4,3,2
β
β β β
벨λ‘κ·Έ λ°λ¦¬λ©΄ μλλλ°...μ΄λ―Έγ
γ
λ°λ €λ²λ €μ κ³ ν΅λ°λ μ€ ..