<script> <BR>Array.prototype.swap = function(i, j) <BR>{ <BR>var temp = this[i]; <BR>this[i] = this[j]; <BR>this[j] = temp; <BR>} <br><br>Array.prototype.bubbleSort = function() <BR>{ <BR>for (var i = this.length - 1; i > 0; --i) <BR>{ <BR>for (var j = 0; j < i; ++j) <BR>{ <BR>if (this[j] > this[j + 1]) this.swap(j, j + 1); <BR>} <BR>} <BR>} <br><br>Array.prototype.selectionSort = function() <BR>{ <BR>for (var i = 0; i < this.length; ++i) <BR>{ <BR>var index = i; <BR>for (var j = i + 1; j < this.length; ++j) <BR>{ <BR>if (this[j] < this[index]) index = j; <BR>} <BR>this.swap(i, index); <BR>} <BR>} <br><br>Array.prototype.insertionSort = function() <BR>{ <BR>for (var i = 1; i < this.length; ++i) <BR>{ <BR>var j = i, value = this[i]; <BR>while (j > 0 && this[j - 1] > value) <BR>{ <BR>this[j] = this[j - 1]; <BR>--j; <BR>} <BR>this[j] = value; <BR>} <BR>} <br><br>Array.prototype.shellSort = function() <BR>{ <BR>for (var step = this.length >> 1; step > 0; step >>= 1) <BR>{ <BR>for (var i = 0; i < step; ++i) <BR>{ <BR>for (var j = i + step; j < this.length; j += step) <BR>{ <BR>var k = j, value = this[j]; <BR>while (k >= step && this[k - step] > value) <BR>{ <BR>this[k] = this[k - step]; <BR>k -= step; <BR>} <BR>this[k] = value; <BR>} <BR>} <BR>} <BR>} <br><br>Array.prototype.quickSort = function(s, e) <BR>{ <BR>if (s == null) s = 0; <BR>if (e == null) e = this.length - 1; <BR>if (s >= e) return; <BR>this.swap((s + e) >> 1, e); <BR>var index = s - 1; <BR>for (var i = s; i <= e; ++i) <BR>{ <BR>if (this[i] <= this[e]) this.swap(i, ++index); <BR>} <BR>this.quickSort(s, index - 1); <BR>this.quickSort(index + 1, e); <BR>} <br><br>Array.prototype.stackQuickSort = function() <BR>{ <BR>var stack = [0, this.length - 1]; <BR>while (stack.length > 0) <BR>{ <BR>var e = stack.pop(), s = stack.pop(); <BR>if (s >= e) continue; <BR>this.swap((s + e) >> 1, e); <BR>var index = s - 1; <BR>for (var i = s; i <= e; ++i) <BR>{ <BR>if (this[i] <= this[e]) this.swap(i, ++index); <BR>} <BR>stack.push(s, index - 1, index + 1, e); <BR>} <BR>} <br><br>Array.prototype.mergeSort = function(s, e, b) <BR>{ <BR>if (s == null) s = 0; <BR>if (e == null) e = this.length - 1; <BR>if (b == null) b = new Array(this.length); <BR>if (s >= e) return; <BR>var m = (s + e) >> 1; <BR>this.mergeSort(s, m, b); <BR>this.mergeSort(m + 1, e, b); <BR>for (var i = s, j = s, k = m + 1; i <= e; ++i) <BR>{ <BR>b[i] = this[(k > e || j <= m && this[j] < this[k]) ? j++ : k++]; <BR>} <BR>for (var i = s; i <= e; ++i) this[i] = b[i]; <BR>} <br><br>Array.prototype.heapSort = function() <BR>{ <BR>for (var i = 1; i < this.length; ++i) <BR>{ <BR>for (var j = i, k = (j - 1) >> 1; k >= 0; j = k, k = (k - 1) >> 1) <BR>{ <BR>if (this[k] >= this[j]) break; <BR>this.swap(j, k); <BR>} <BR>} <BR>for (var i = this.length - 1; i > 0; --i) <BR>{ <BR>this.swap(0, i); <BR>for (var j = 0, k = (j + 1) << 1; k <= i; j = k, k = (k + 1) << 1) <BR>{ <BR>if (k == i || this[k] < this[k - 1]) --k; <BR>if (this[k] <= this[j]) break; <BR>this.swap(j, k); <BR>} <BR>} <BR>} <br><br>function generate() <BR>{ <BR>var max = parseInt(txtMax.value), count = parseInt(txtCount.value); <BR>if (isNaN(max) || isNaN(count)) <BR>{ <BR>alert("个数和最大值必须是一个整数"); <BR>return; <BR>} <BR>var array = []; <BR>for (var i = 0; i < count; ++i) array.push(Math.round(Math.random() * max)); <BR>txtInput.value = array.join("\n"); <BR>txtOutput.value = ""; <BR>} <br><br>function demo(type) <BR>{ <BR>var array = txtInput.value == "" ? [] : txtInput.value.replace().split("\n"); <BR>for (var i = 0; i < array.length; ++i) array[i] = parseInt(array[i]); <BR>var t1 = new Date(); <BR>eval("array." + type + "Sort()"); <BR>var t2 = new Date(); <BR>lblTime.innerText = t2.valueOf() - t1.valueOf(); <BR>txtOutput.value = array.join("\n"); <BR>} <BR></script>
| 随机数个数 最大随机数 耗时(毫秒): | |

JavaScript字符串替换方法详解及常见问题解答 本文将探讨两种在JavaScript中替换字符串字符的方法:在JavaScript代码内部替换和在网页HTML内部替换。 在JavaScript代码内部替换字符串 最直接的方法是使用replace()方法: str = str.replace("find","replace"); 该方法仅替换第一个匹配项。要替换所有匹配项,需使用正则表达式并添加全局标志g: str = str.replace(/fi

因此,在这里,您准备好了解所有称为Ajax的东西。但是,到底是什么? AJAX一词是指用于创建动态,交互式Web内容的一系列宽松的技术。 Ajax一词,最初由Jesse J创造

10款趣味横生的jQuery游戏插件,让您的网站更具吸引力,提升用户粘性!虽然Flash仍然是开发休闲网页游戏的最佳软件,但jQuery也能创造出令人惊喜的效果,虽然无法与纯动作Flash游戏媲美,但在某些情况下,您也能在浏览器中获得意想不到的乐趣。 jQuery井字棋游戏 游戏编程的“Hello world”,现在有了jQuery版本。 源码 jQuery疯狂填词游戏 这是一个填空游戏,由于不知道单词的上下文,可能会产生一些古怪的结果。 源码 jQuery扫雷游戏

本教程演示了如何使用jQuery创建迷人的视差背景效果。 我们将构建一个带有分层图像的标题横幅,从而创造出令人惊叹的视觉深度。 更新的插件可与JQuery 1.6.4及更高版本一起使用。 下载

本文讨论了在浏览器中优化JavaScript性能的策略,重点是减少执行时间并最大程度地减少对页面负载速度的影响。

本文演示了如何使用jQuery和ajax自动每5秒自动刷新DIV的内容。 该示例从RSS提要中获取并显示了最新的博客文章以及最后的刷新时间戳。 加载图像是选择

Matter.js是一个用JavaScript编写的2D刚体物理引擎。此库可以帮助您轻松地在浏览器中模拟2D物理。它提供了许多功能,例如创建刚体并为其分配质量、面积或密度等物理属性的能力。您还可以模拟不同类型的碰撞和力,例如重力摩擦力。 Matter.js支持所有主流浏览器。此外,它也适用于移动设备,因为它可以检测触摸并具有响应能力。所有这些功能都使其值得您投入时间学习如何使用该引擎,因为这样您就可以轻松创建基于物理的2D游戏或模拟。在本教程中,我将介绍此库的基础知识,包括其安装和用法,并提供一


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

Dreamweaver CS6
视觉化网页开发工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具