各位英雄女侠可否帮一下忙啊!!!!!! 字符串数组 排序前——abc bcd bcf bbb acd排序后——abc acd bbb bcd bcf说明:排序过程中是逐个字符进行对比要求:不能用equals()方法 不能用sort()方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //用最简单的冒泡就好了<script type="text/javascript"> function swap(items, firstIndex, secondIndex) { var temp = items[firstIndex]; items[firstIndex] = items[secondIndex]; items[secondIndex] = temp; } function bubbleSort(items) { var len = items.length; if(len <= 0) return false; for(var i = 0; i < len; i++) { for(var j = 0, stop = len - i; j < stop; j++) { if(items[j] > items[j + 1]) { swap(items, j, j + 1); } } } return items; } document.write(bubbleSort("abc bcd bcf bbb acd".split(' ')).join(' ')) </script> 为什么不能使用sort()方法?sort()一步就可以解决问题了!!! jquery 如何让div 显示 html 标签内容呢? 急求 请介绍个手机端使用的拖拽插件 iframe无法显示,求助,急,在线等 求jq的日期时间控件 谁帮我解一下这个页面中的部分加密代码呢? 用JAVASCRIPT获取到客户得到的数据,怎么传到数据库存储代码? 时间显示并移动(急) 下面创建的INPUT为什么不显示?? 如何根据下拉框的选择来决定一组单选按钮的默认选择? 如何获取一个Iframe里的内容 JS写paddingLeft在IE下有效,在FIREFOX下无效!应该怎么写? js dropdownlist怎么选择指定值
//用最简单的冒泡就好了
<script type="text/javascript">
function swap(items, firstIndex, secondIndex) {
var temp = items[firstIndex];
items[firstIndex] = items[secondIndex];
items[secondIndex] = temp;
}
function bubbleSort(items) {
var len = items.length;
if(len <= 0) return false;
for(var i = 0; i < len; i++) {
for(var j = 0, stop = len - i; j < stop; j++) {
if(items[j] > items[j + 1]) {
swap(items, j, j + 1);
}
}
}
return items;
} document.write(bubbleSort("abc bcd bcf bbb acd".split(' ')).join(' '))
</script>