From 04ff3346ec18924ac0445166c04fb3af84b615eb Mon Sep 17 00:00:00 2001
From: Orestis <orestis.malaspinas@pm.me>
Date: Thu, 30 Sep 2021 20:35:20 +0200
Subject: [PATCH] added swap

---
 examples/tri_selection/tri.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/examples/tri_selection/tri.c b/examples/tri_selection/tri.c
index 9e5811c..1702ef6 100644
--- a/examples/tri_selection/tri.c
+++ b/examples/tri_selection/tri.c
@@ -15,6 +15,12 @@ void find_min(double tab[], int i0, int *ind, double *min) {
     }
 }
 
+void swap(double *a, double *b) {
+    double tmp = *a;
+    *a         = *b;
+    *b         = tmp;
+}
+
 int main() {
     srand(time(NULL));
     double tab[SIZE];
@@ -26,9 +32,7 @@ int main() {
         double min  = tab[i];
         int ind_min = i;
         find_min(tab, i, &ind_min, &min);
-        double tmp   = tab[i];
-        tab[i]       = min;
-        tab[ind_min] = tmp;
+        swap(&tab[i], &tab[ind_min]);
     }
 
     for (int i = 0; i < SIZE; ++i) {
-- 
GitLab