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 <stddef.h>
 9#include <stdbool.h>
10#include <assert.h>
11
12#define MAX 6
13
14extern void quebex_symbolic_array(void *, size_t, size_t, const char *);
15
16void bubble_sort(int* array_sort)
17{
18    bool is_sorted = false;
19
20    /* keep iterating over entire array
21     * and swaping elements out of order
22     * until it is sorted */
23    while (!is_sorted)
24    {
25        is_sorted = true;
26
27        /* iterate over all elements */
28        for (int i = 0; i < MAX - 1; i++)
29        {
30            /* check if adjacent elements are out of order */
31            if (array_sort[i] > array_sort[i + 1])
32            {
33                /* swap elements */
34                int change_place = array_sort[i];
35                array_sort[i] = array_sort[i + 1];
36                array_sort[i + 1] = change_place;
37                /* elements out of order were found
38                 * so we reset the flag to keep ordering
39                 * until no swap operations are executed */
40                is_sorted = false;
41            }
42        }
43    }
44}
45
46int
47main(void)
48{
49    int array[MAX];
50
51    quebex_symbolic_array(array, MAX, sizeof(int), "array");
52    bubble_sort(array);
53
54    return 0;
55}