复制代码 代码如下:
l = [6, 2, 4, 1, 98, 34, 5, 9, 23, 8, 10, 32]
//冒泡排序
/*function bubbleSort(arr) {
newarr = arr.slice()
if (newarr.length <= 2) return newarr
for (var i = 0; i < newarr.length - 1; i++) {
for (var j = 0; j < newarr.length - i - 1; j++) {
if (newarr[j] > newarr[j + 1]) {
newarr[j] = [newarr[j + 1], newarr[j + 1] = newarr[j]][0]
}
}
}
return newarr
}
console.log(l)
result = bubbleSort(l)
console.log(result)*/
//快速排序
/*function quickSort(arr) {
if (arr.length <= 1) return arr;
var left = [],
right = [],
middle = [];
var mid = arr[Math.floor(arr.length / 2)]
for (var i = 0; i < arr.length; i++) {
if (arr[i] < mid) {
left.push(arr[i]);
} else if (arr[i] > mid) {
right.push(arr[i]);
} else {
middle.push(mid);
}
}
return [].concat(quickSort(left), middle, quickSort(right))
}
var results = quickSort(l)
console.log(results)
*/
//选择排序
/*function selectSort(arr) {
var min = 9999,
minindex = 0;
var left = [],
right = arr.slice();
if (arr.length <= 1) return arr;
for (var i = 0; i < arr.length; i++) {
if (arr[i] <= min) {
min = arr[i];
minindex = i;
}
}
left.push(min);
right.splice(minindex, 1);
return [].concat(left, selectSort(right))
}
var results = selectSort(l)
console.log(results)*/
//插入排序
/*function insertSort(arr) {
var tmp;
for (var i = 1; i < arr.length; i++) {
tmp = arr[i];
for (var j = i; j > 0; j--) {
if (arr[j - 1] > tmp) {
arr[j] = arr[j - 1];
} else {
break;
}
}
arr[j] = tmp;
}
return arr;
}
var results = insertSort(l)
console.log(results)*/
//木桶排序
/*function bucketSort(arr){
var bucket = [];
var newarr = [];
for (var i = 0; i < arr.length; i++) {
bucket[arr[i]] = arr[i];
}
for (var i = 0; i < bucket.length; i++) {
if (bucket[i] !== undefined){
newarr.push(bucket[i])
}
}
return newarr;
}
var results = bucketSort(l)
console.log(results)*/
//鸽巢排序,非负整数
/*function pigeonholeSort(arr){
var tempArr = [];
for(var i=0,l=arr.length;i<l;i++){
tempArr[arr[i]] = (tempArr[arr[i]]+1)||1 ;
}
var result = [],count;
for(var k=0;k<tempArr.length;k++){
count = tempArr[k];
if(count){
for(var i=0;i<count;i++){
result.push(k);
}
}
}
return result;
}
var results = pigeonholeSort(l)
console.log(results)*/
//归并排序
/*function mergeSort(arr) {
if (arr.length <= 1) return arr;
var mid = Math.floor(arr.length / 2);
var left = MergeSort(arr.slice(0, mid));
var right = MergeSort(arr.slice(mid));
var result = [];
while (left.length && right.length) {
if (left[left.length - 1] <= right[0]) {
result = result.concat(left);
left = [];
} else if (right[right.length - 1] < left[0]) {
result = result.concat(right);
right = [];
} else {
if (right[0] < left[0]) {
result.push(right.shift());
} else {
result.push(left.shift());
}
}
}
result = result.concat(left, right);
return result;
}*/
/*function mergeSort(arr) {
var merge = function(left, right) {
var result = [];
while (left.length > 0 && right.length > 0) {
if (left[0] < right[0]) {
result.push(left.shift());
} else {
result.push(right.shift());
}
}
return result.concat(left).concat(right);
}
if (arr.length == 1) return arr;
var middle = Math.floor(arr.length / 2),
left = arr.slice(0, middle),
right = arr.slice(middle);
return merge(mergeSort(left), mergeSort(right));
}
var results = mergeSort(l)
console.log(results)
*/
//堆排序
/*function heapSort(arr) {
var findRoot = function(arr, p, length) {
p = p || 0;
length = length || arr.length;
var self = arguments.callee;
var l = p * 2 + 1;
var r = (p + 1) * 2;
var left, right;
if (l < length) left = self(arr, l, length);
if (r < length) right = self(arr, r, length);
if (left > arr[p]) arr[p] = [left, arr[l] = arr[p]][0];
if (right > arr[p]) arr[p] = [right, arr[r] = arr[p]][0];
return arr[p];
};
for (var i = arr.length; i > 0; i--) {
findRoot(arr, 0, i);
arr[i - 1] = [arr[0], arr[0] = arr[i - 1]][0];
}
return arr;
}
var results = heapSort(l)
console.log(results)*/
//奇偶排列
/*function oddEvenSort(arr) {
var swaped = true,
k = 0;
while (swaped) {
if (k > 0) swaped = false;
for (var i = k; i < arr.length - 1; i += 2) {
if (arr[i]>arr[i+1]) {
arr[i] = [ arr[i+1], arr[i+1]=arr[i] ][0];
swaped = true;
}
}
k = [1, 0][k]
}
return arr;
}
var results = oddEvenSort(l)
console.log(results)*/
function oddEvenSort(arr) {
var swaped = true;
while (swaped) {
swaped = false;
for (var i = 0; i < arr.length; i += 2) {
if (arr[i] > arr[i + 1]) {
arr[i] = [arr[i + 1], arr[i + 1] = arr[i]][0];
swaped = true;
}
}
for (var i = 1; i < arr.length; i += 2) {
if (arr[i] > arr[i + 1]) {
arr[i] = [arr[i + 1], arr[i + 1] = arr[i]][0];
swaped = true;
}
}
}
return arr;
}
var results = oddEvenSort(l)
console.log(results)
l = [6, 2, 4, 1, 98, 34, 5, 9, 23, 8, 10, 32]
//冒泡排序
/*function bubbleSort(arr) {
newarr = arr.slice()
if (newarr.length <= 2) return newarr
for (var i = 0; i < newarr.length - 1; i++) {
for (var j = 0; j < newarr.length - i - 1; j++) {
if (newarr[j] > newarr[j + 1]) {
newarr[j] = [newarr[j + 1], newarr[j + 1] = newarr[j]][0]
}
}
}
return newarr
}
console.log(l)
result = bubbleSort(l)
console.log(result)*/
//快速排序
/*function quickSort(arr) {
if (arr.length <= 1) return arr;
var left = [],
right = [],
middle = [];
var mid = arr[Math.floor(arr.length / 2)]
for (var i = 0; i < arr.length; i++) {
if (arr[i] < mid) {
left.push(arr[i]);
} else if (arr[i] > mid) {
right.push(arr[i]);
} else {
middle.push(mid);
}
}
return [].concat(quickSort(left), middle, quickSort(right))
}
var results = quickSort(l)
console.log(results)
*/
//选择排序
/*function selectSort(arr) {
var min = 9999,
minindex = 0;
var left = [],
right = arr.slice();
if (arr.length <= 1) return arr;
for (var i = 0; i < arr.length; i++) {
if (arr[i] <= min) {
min = arr[i];
minindex = i;
}
}
left.push(min);
right.splice(minindex, 1);
return [].concat(left, selectSort(right))
}
var results = selectSort(l)
console.log(results)*/
//插入排序
/*function insertSort(arr) {
var tmp;
for (var i = 1; i < arr.length; i++) {
tmp = arr[i];
for (var j = i; j > 0; j--) {
if (arr[j - 1] > tmp) {
arr[j] = arr[j - 1];
} else {
break;
}
}
arr[j] = tmp;
}
return arr;
}
var results = insertSort(l)
console.log(results)*/
//木桶排序
/*function bucketSort(arr){
var bucket = [];
var newarr = [];
for (var i = 0; i < arr.length; i++) {
bucket[arr[i]] = arr[i];
}
for (var i = 0; i < bucket.length; i++) {
if (bucket[i] !== undefined){
newarr.push(bucket[i])
}
}
return newarr;
}
var results = bucketSort(l)
console.log(results)*/
//鸽巢排序,非负整数
/*function pigeonholeSort(arr){
var tempArr = [];
for(var i=0,l=arr.length;i<l;i++){
tempArr[arr[i]] = (tempArr[arr[i]]+1)||1 ;
}
var result = [],count;
for(var k=0;k<tempArr.length;k++){
count = tempArr[k];
if(count){
for(var i=0;i<count;i++){
result.push(k);
}
}
}
return result;
}
var results = pigeonholeSort(l)
console.log(results)*/
//归并排序
/*function mergeSort(arr) {
if (arr.length <= 1) return arr;
var mid = Math.floor(arr.length / 2);
var left = MergeSort(arr.slice(0, mid));
var right = MergeSort(arr.slice(mid));
var result = [];
while (left.length && right.length) {
if (left[left.length - 1] <= right[0]) {
result = result.concat(left);
left = [];
} else if (right[right.length - 1] < left[0]) {
result = result.concat(right);
right = [];
} else {
if (right[0] < left[0]) {
result.push(right.shift());
} else {
result.push(left.shift());
}
}
}
result = result.concat(left, right);
return result;
}*/
/*function mergeSort(arr) {
var merge = function(left, right) {
var result = [];
while (left.length > 0 && right.length > 0) {
if (left[0] < right[0]) {
result.push(left.shift());
} else {
result.push(right.shift());
}
}
return result.concat(left).concat(right);
}
if (arr.length == 1) return arr;
var middle = Math.floor(arr.length / 2),
left = arr.slice(0, middle),
right = arr.slice(middle);
return merge(mergeSort(left), mergeSort(right));
}
var results = mergeSort(l)
console.log(results)
*/
//堆排序
/*function heapSort(arr) {
var findRoot = function(arr, p, length) {
p = p || 0;
length = length || arr.length;
var self = arguments.callee;
var l = p * 2 + 1;
var r = (p + 1) * 2;
var left, right;
if (l < length) left = self(arr, l, length);
if (r < length) right = self(arr, r, length);
if (left > arr[p]) arr[p] = [left, arr[l] = arr[p]][0];
if (right > arr[p]) arr[p] = [right, arr[r] = arr[p]][0];
return arr[p];
};
for (var i = arr.length; i > 0; i--) {
findRoot(arr, 0, i);
arr[i - 1] = [arr[0], arr[0] = arr[i - 1]][0];
}
return arr;
}
var results = heapSort(l)
console.log(results)*/
//奇偶排列
/*function oddEvenSort(arr) {
var swaped = true,
k = 0;
while (swaped) {
if (k > 0) swaped = false;
for (var i = k; i < arr.length - 1; i += 2) {
if (arr[i]>arr[i+1]) {
arr[i] = [ arr[i+1], arr[i+1]=arr[i] ][0];
swaped = true;
}
}
k = [1, 0][k]
}
return arr;
}
var results = oddEvenSort(l)
console.log(results)*/
function oddEvenSort(arr) {
var swaped = true;
while (swaped) {
swaped = false;
for (var i = 0; i < arr.length; i += 2) {
if (arr[i] > arr[i + 1]) {
arr[i] = [arr[i + 1], arr[i + 1] = arr[i]][0];
swaped = true;
}
}
for (var i = 1; i < arr.length; i += 2) {
if (arr[i] > arr[i + 1]) {
arr[i] = [arr[i + 1], arr[i + 1] = arr[i]][0];
swaped = true;
}
}
}
return arr;
}
var results = oddEvenSort(l)
console.log(results)
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月16日
2024年11月16日
- 林俊吉.2012-将你惜命命【美华】【WAV+CUE】
- 晓雅《分享》DTS-WAV
- 黑鸭子2008-飞歌[首版][WAV+CUE]
- 黄乙玲1989-水泼落地难收回[日本天龙版][WAV+CUE]
- 周深《反深代词》[先听版][FLAC/分轨][310.97MB]
- 姜育恒1984《什么时候·串起又散落》台湾复刻版[WAV+CUE][1G]
- 那英《如今》引进版[WAV+CUE][1G]
- 蔡幸娟.1991-真的让我爱你吗【飞碟】【WAV+CUE】
- 群星.2024-好团圆电视剧原声带【TME】【FLAC分轨】
- 陈思安.1990-国语钢琴酒吧5CD【欣代唱片】【WAV+CUE】
- 莫文蔚《莫后年代20周年世纪典藏》3CD[WAV+CUE][2G]
- 张惠妹《我要快乐》华纳[WAV+CUE][1G]
- 罗大佑1982《之乎者也》无法盗版的青春套装版 [WAV+CUE][1G]
- 曾庆瑜1989-款款柔情[日本东芝版][WAV+CUE]
- Scelsi-IntegraledesquatuorsacordesetTrioacordes-QuatuorMolinari(2024)[24bit-WAV]