Bubble Sort

    0

    2

    Giovanny Gongora

    Codiga's C Recipes

    Bubble Sort implementation

    #include <stdbool.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    void bubbleSort(int *A, int n) {
    	bool isSwapped;
    	int i, temp;
    	do {
    		isSwapped = false;
    		for (i = 0; i < n; i++) {
    			if (A[i - 1] > A[i]) {
    				temp = A[i - 1];
    				A[i - 1] = A[i];
    				A[i] = temp;
    				isSwapped = true;
    			}
    		}
    	} while (isSwapped);
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.