Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdbbeff6

Browse files
committed
add 算法
1 parentb5a4c8c commitdbbeff6

File tree

5 files changed

+42
-41
lines changed

5 files changed

+42
-41
lines changed

‎算法与数据结构学习/algorithms/sort/quick-sort/quick-sort.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function quickSort(arr, low, high) {
88

99
functionadjustArr(arr,low,high){
1010
letpivot=arr[low];
11-
1211
while(low<high){
1312
while(arr[high]>pivot)
1413
high--;
@@ -24,4 +23,18 @@ function adjustArr(arr, low, high) {
2423

2524
letarr=[72,6,57,88,60,42,83,73,48,85];
2625
quickSort(arr,0,arr.length-1);
27-
console.log(arr);
26+
console.log(arr);
27+
28+
functionquickSort(arr){
29+
constpivot=arr[0];
30+
constleft=[];
31+
constright=[];
32+
33+
if(arr.length<2){returnarr;}
34+
35+
for(leti=1,len=arr.length;i<len;i++){
36+
arr[i]<pivot ?left.push(arr[i]) :right.push(arr[i]);
37+
}
38+
39+
returnquickSort(left).concat([pivot],quickSort(right));
40+
}
Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
functionquickSort(arr,low,high){
2-
if(low<high){
3-
// 调整数组
4-
leti=adjustArr(arr,low,high);
5-
// 分治
6-
quickSort(arr,low,i-1);
7-
quickSort(arr,i+1,high);
8-
}
9-
}
10-
11-
functionadjustArr(arr,low,high){
12-
letpivot=arr[low];
1+
varmyPow=function(x,n){
2+
returnn>0 ?quickMul(x,n) :1.0/quickMul(x,-n);
3+
};
134

14-
while(low<high){
15-
while(low<high&&arr[high]>pivot)
16-
high--;
17-
arr[low]=arr[high];
18-
while(low<high&&arr[low]<pivot)
19-
low++;
20-
arr[high]=arr[low];
5+
varquickMul=function(x,N){
6+
if(N==0){
7+
return1.0
218
}
22-
23-
arr[low]=pivot;
24-
returnlow;
9+
lety=quickMul(x,Math.floor());
10+
returnN%2==0 ?y*y :y*y*x;
2511
}
2612

27-
letarr=[72,6,57,88,60,42,83,73,48,85];
28-
quickSort(arr,0,arr.length-1);
29-
console.log(arr);
13+
console.log(myPow(2,10));
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
importHashTablefrom'./HashTable';
1+
// let k1 = [1,2,3];
2+
// let k2 = [3,4,5];
3+
// let k3 = [3,4,5];
4+
// let arr = [[k1, 'foo'], [k2, 'bar']];
25

3-
lethashTable=newHashTable();
6+
//letkeys =arr.map(item => item[0]);
47

5-
hashTable.set('a','sky-old');
6-
hashTable.set('a','sky');
7-
hashTable.set('b','sea');
8-
hashTable.set('c','earth');
9-
hashTable.set('d','ocean');
8+
// console.log();
109

11-
hashTable.buckets[1].toString();
12-
console.log(hashTable.getKeys())
13-
console.log(hashTable.has);
1410

11+
// console.log(keys.indexOf(k3));
12+
13+
letarr=[1,2,3];
14+
letobj={
15+
arr:arr
16+
}
17+
18+
console.log(obj.arr);

‎算法与数据结构学习/data-structures/heap/Heap.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
exportdefaultclassHeap{
22
constructor(params){
3-
43
// 不能直接通过 new 来创建堆
54
if(new.target===Heap){
65
thrownewTypeError('Cannot construct Heap instance directly');
76
}
8-
97
this.heapContainer=[];
10-
118
}
129

13-
1410
/**
1511
* 获取左孩子的下标
1612
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
constp=Promise.resolve(1);
2+
3+
p.then(console.log)
4+
p.then(console.log)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp