C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
bubble_sort.c File Reference

Bubble sort with early-exit optimization. More...

#include "sorts.h"
#include <stdbool.h>
#include <string.h>

Go to the source code of this file.

Functions

void bubble_sort_ints (int *arr, size_t n)
 
void bubble_sort_strings (char **arr, size_t n)
 

Detailed Description

Bubble sort with early-exit optimization.

Repeatedly walk the array, swapping adjacent out-of-order pairs. If a full pass produced no swaps the array is sorted — bail early. Stable, O(n²) worst, O(n) best.

Definition in file bubble_sort.c.

Function Documentation

◆ bubble_sort_ints()

void bubble_sort_ints ( int *  arr,
size_t  n 
)

Definition at line 30 of file bubble_sort.c.

◆ bubble_sort_strings()

void bubble_sort_strings ( char **  arr,
size_t  n 
)

Definition at line 14 of file bubble_sort.c.

Referenced by algo_from_name().