Saturday, August 6, 2016

Swapping without using extra variable

function swap (a, b){ // 5,7
    a = b - a; // 7-5 = 2
    b = b - a; // 7-2 = 5
    a = a + b; // 2 + 5 = 7
}

No comments:

Post a Comment