#include <algorithm>
      #include <concepts>
      #include <vector>
      
      namespace codiga::sort {
      template <typename T>
      requires std::totally_ordered<T>
      void bubble_sort(std::vector<T>& array){
        auto swapped = false;
        do {
          swapped = false;
          for (auto index = 0; index < array.size() - 1; index++) {
            if (array[index] > array[index + 1]) {
              std::swap(array[index], array[index + 1]);
              swapped = true;
            }
          }
        } while (swapped == true);
      }
      }
      
      Cpp language logo

      Bubble Sort

      Codiga's C++ Recipes

      Bubble sort algorithm

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.