Bubble Sort

    0

    0

    Giovanny Gongora

    Codiga's C++ Recipes

    Use Bubble Sort Algorithm

    #include <iostream>
    
    void BubbleSort(int *array, int n) {
      bool swapped = true;
      int j = 0;
      int temp;
      while (swapped) {
        swapped = false;
        j++;
        for (int i = 0; i < n - j; ++i) {
          if (array[i] > array[i + 1]) {
            temp = array[i];
            array[i] = array[i + 1];
            array[i + 1] = temp;
            swapped = true;
          }
        }
      }
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.