标签:冒泡排序 冒泡 排序 i++ for length 选择排序 选择 pre
冒泡排序
for (let j = 0; j < a.length - 1; j++) { for (let i = 0; i < a.length - 1 - j; i++) { if (a[i] > a[i + 1]) { temp = a[i + 1]; a[i + 1] = a[i]; a[i] = temp; } } }
选择排序
for (let j = 0; j <length- 1;j++) { for (let i = j; i < length- 1; i++) { if (a[j] > a[i + 1]) { temp = a[j]; a[j] = a[i + 1]; a[i + 1] = temp; } } }
标签:冒泡排序 冒泡 排序 i++ for length 选择排序 选择 pre
原文地址:https://www.cnblogs.com/lee1-w/p/11489275.html