bubble_sort

  • 2022-12-14
  • 浏览 (357)

bubble_sort.cpp 源码

//
// Created by roseduan on 2021/9/21.
//
#include "vector"
#include "iostream"
using namespace std;

void BubbleSort(vector<int>& data) {
    for (int i = 0; i < data.size() - 1; ++i) {
        for (int j = i + 1; j < data.size(); ++j) {
            if (data[i] > data[j]) {
                int temp = data[i];
                data[i] = data[j];
                data[j] = temp;
            }
        }
    }
}

int main() {
    vector<int> data {6};
    BubbleSort(data);

    for (int i : data) {
        cout << i << endl;
    }
}

你可能感兴趣的文章

merge_sort

selection_sort

0  赞