Bubble sort · Sắp xếp nổi bọt
Bubble sort
Sort an array into ascending order in place using bubble sort: walk through the array comparing each pair of neighbours and swapping them if they're in the wrong order. After each full pass the largest remaining value has "bubbled" to the end, so repeat until everything is sorted.
Sắp xếp nổi bọt
Sắp xếp mảng theo thứ tự tăng dần tại chỗ bằng thuật toán sort bong bóng: duyệt qua mảng so sánh từng cặp phần tử kề nhau và hoán đổi nếu chúng nằm sai thứ tự. Sau mỗi lượt duyệt hoàn chỉnh, giá trị lớn nhất còn lại đã "nổi" lên cuối, nên lặp lại cho đến khi tất cả được sắp xếp.
Complete void bubble_sort(int *a, int n) to sort the n elements into ascending order, in place. Repeatedly pass through the array swapping any out-of-order neighbours. · Hoàn thành void bubble_sort(int *a, int n) để sắp xếp n phần tử theo thứ tự tăng dần, tại chỗ. Liên tục duyệt qua mảng và hoán đổi bất kỳ cặp lân cận nào sai thứ tự.
Click Run to see the output here. · Nhấn Chạy để xem kết quả ở đây.