Browse Source

optimize swap

Chris Cromer 7 months ago
parent
commit
6ff4147448
Signed by: Chris Cromer <chris@cromer.cl> GPG Key ID: 39CC813FF3C8708A
1 changed files with 6 additions and 3 deletions
  1. 6
    3
      src/swap.c

+ 6
- 3
src/swap.c View File

@@ -19,7 +19,10 @@
19 19
  * @param yp Segundo valor
20 20
  */
21 21
 void swap(int *xp, int *yp) {
22
-	int temp = *xp;
23
-	*xp = *yp;
24
-	*yp = temp;
22
+	if (xp == yp) {
23
+		return;
24
+	}
25
+	*xp = *xp + *yp;
26
+	*yp = *xp - *yp;
27
+	*xp = *xp - *yp;
25 28
 }

Loading…
Cancel
Save