File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -1788,7 +1788,6 @@ function selectionSort() {
17881788### JavaScript算法- 插入排序
17891789
17901790* 插入排序
1791-
17921791* 插入排序有两个循环,外循环将数组元素挨个移动,而内循环则对外循环中选中的元素及它后面的那个元素进行比较。如果外循环中选中的元素比内循环中选中的元素小,那么数组会向右移动,为内循环中的这个元素腾出位置。
17931792
17941793< p align= " center" >< img src= " http://www.2cto.com/uploadfile/Collfiles/20160918/20160918092144589.gif" / >< / p>
@@ -1808,6 +1807,37 @@ function insertionSort() {
18081807}
18091808` ` `
18101809
1810+ ## 08 - 05
1811+ ### JavaScript算法- 希尔排序
1812+
1813+ * 希尔排序
1814+ * 这个算法在插入排序的基础上作出了很大的改善。希尔排序的核心理念与插入排序不同,它会首先比较距离较远的元素,而非相邻的元素。和简单的比较相邻元素相比,使用这种方案可以使离正确位置很远的元素更快回到适合的位置。当开始用这个算法遍历数据集时,所有元素之间的距离会不断减小,直到处理到数据集的末尾,这时算法比较的就是相邻元素了。
1815+ * 主要是通过遍历数组中相隔相同位置的元素去比较大小进行排列
1816+
1817+ ` ` ` JavaScript
1818+ function shellsort() {
1819+ for (var g = 0; i < this.gaps.length; ++g) {
1820+ for (var i = 0; i < this.dataStore.length; ++i) {
1821+ var temp = this.dataStore[i];
1822+ for (var j = i; j >= this.gaps[g] && this.dataStore[j-this.gaps[g]] > temp; j -= this.gaps[g]) {
1823+ this.dataStore[j] = this.dataStore[j-this.gaps[g]];
1824+ }
1825+ this.dataStore[j] = temp;
1826+ }
1827+ }
1828+ }
1829+ ` ` `
1830+
1831+ * CArray构造函数中添加
1832+
1833+ ` ` ` JavaScript
1834+ this.gaps = [5,3,1];
1835+ //并添加一个函数
1836+ function setGap(arr) {
1837+ this.gaps = arr ;
1838+ }
1839+ ` ` `
1840+
18111841## 09 - 01
18121842### JS 基本应用- 函数
18131843
You can’t perform that action at this time.
0 commit comments