1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* This file is part of the coreboot project. */
4 #include <commonlib/helpers.h>
5 #include <commonlib/sort.h>
7 /* Implement a simple Bubble sort algorithm. Reduce the needed number of
8 iterations by taking care of already sorted entries in the list. */
9 void bubblesort(int *v
, size_t num_entries
, sort_order_t order
)
14 /* Make sure there are at least two entries to sort. */
18 for (j
= 0; j
< num_entries
- 1; j
++) {
20 for (i
= 0; i
< num_entries
- j
- 1; i
++) {
23 if (v
[i
] > v
[i
+ 1]) {
29 if (v
[i
] < v
[i
+ 1]) {