1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <commonlib/helpers.h>
4 #include <commonlib/sort.h>
6 /* Implement a simple Bubble sort algorithm. Reduce the needed number of
7 iterations by taking care of already sorted entries in the list. */
8 void bubblesort(int *v
, size_t num_entries
, sort_order_t order
)
13 /* Make sure there are at least two entries to sort. */
17 for (j
= 0; j
< num_entries
- 1; j
++) {
19 for (i
= 0; i
< num_entries
- j
- 1; i
++) {
22 if (v
[i
] > v
[i
+ 1]) {
28 if (v
[i
] < v
[i
+ 1]) {