We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9ea2245 commit 285a117Copy full SHA for 285a117
2-selection_sort.c
@@ -0,0 +1,35 @@
1
+#include "sort.h"
2
+
3
+/**
4
+ * selection_sort - Sorts an array using the selection sort algorithm.
5
+ * @array: The array to sort.
6
+ * @size: The length of the array.
7
+ */
8
+void selection_sort(int *array, size_t size)
9
+{
10
+ size_t i, j, low_index;
11
+ int temp;
12
13
+ if (array != NULL)
14
+ {
15
+ for (i = 0; i < size - 1; i++)
16
17
+ low_index = i;
18
+ for (j = size - 1; j > i; j--)
19
20
+ if (array[j] < array[low_index])
21
22
+ low_index = j;
23
+ } /* End if */
24
+ } /* End for */
25
+ if (i != low_index)
26
27
+ /* Swapping */
28
+ temp = array[i];
29
+ array[l] = array[low_index];
30
+ array[low_index] = temp;
31
+ print_array(array, size);
32
33
34
35
+} /* End function */
0 commit comments