# -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; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up