Bubble sort · 冒泡排序
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.
冒泡排序
用冒泡排序把数组原地按升序排列:遍历数组,比较每一对相邻元素,如果顺序不对就交换。每完成一轮,剩余的最大值就「冒泡」到了末尾,所以重复进行直到全部有序。
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. · 完成 void bubble_sort(int *a, int n),把这 n 个元素原地按升序排序。反复遍历数组,交换任何顺序颠倒的相邻元素。
Click Run to see the output here. · 点击“运行”查看此处输出。