---
# System prepended metadata

title: '-Bubble sort'
tags: [Easy]

---

# -Bubble sort 
###### tags: `Easy`
Bubble: 像泡泡一樣上浮
```cpp=
vector<int> bubbleSort(vector<int> array) {
  // Write your code here.
    if (array.empty())
        return {};
    bool isSorted = false;
    int counter = 0;
    while (!isSorted){
        isSorted = true;
        for (int i = 0; i < array.size() - counter - 1; i++){
            if (array[i] > array[i+1]){
                swap(array[i], array[i+1]);
                isSorted = false;
            }
        }
        counter++;
    }
    return array;
}
```