<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 無盡。

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

禪工作室 13.0.1
強大的PHP整合開發環境

Atom編輯器mac版下載
最受歡迎的的開源編輯器

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Dreamweaver Mac版
視覺化網頁開發工具