冒泡排序
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
冒泡排序
用冒泡排序把数组原地按升序排列:遍历数组,比较每一对相邻元素,如果顺序不对就交换。每完成一轮,剩余的最大值就「冒泡」到了末尾,所以重复进行直到全部有序。
难度 4/5 · 今日首次完成可获 280 金币及少量额外奖励
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.
点击“运行”查看此处输出。