quebex

A software analysis framework built around the QBE intermediate language

git clone https://git.8pit.net/quebex.git

 1// SPDX-FileCopyrightText: 2021 Gabriel Fioravante
 2// SPDX-FileCopyrightText: 2025 Sören Tempel <soeren+git@soeren-tempel.net>
 3//
 4// SPDX-License-Identifier: GPL-3.0-only
 5
 6// Taken from: https://github.com/TheAlgorithms/C/blob/f241de90e1691dc7cfcafcbecd89ef12db922e6b/sorting/bubble_sort_2.c
 7
 8#include <stdbool.h>
 9#include <assert.h>
10
11#define MAX 4
12
13void bubble_sort(int* array_sort)
14{
15    bool is_sorted = false;
16
17    /* keep iterating over entire array
18     * and swaping elements out of order
19     * until it is sorted */
20    while (!is_sorted)
21    {
22        is_sorted = true;
23
24        /* iterate over all elements */
25        for (int i = 0; i < MAX - 1; i++)
26        {
27            /* check if adjacent elements are out of order */
28            if (array_sort[i] > array_sort[i + 1])
29            {
30                /* swap elements */
31                int change_place = array_sort[i];
32                array_sort[i] = array_sort[i + 1];
33                array_sort[i + 1] = change_place;
34                /* elements out of order were found
35                 * so we reset the flag to keep ordering
36                 * until no swap operations are executed */
37                is_sorted = false;
38            }
39        }
40    }
41}
42
43unsigned entry(int a, int b, int c, int d)
44{
45    int array[MAX];
46
47    array[0] = a;
48    array[1] = b;
49    array[2] = c;
50    array[3] = d;
51
52    bubble_sort(array);
53    return 0;
54}