Skip to content

Commit ed6e44a

Browse files
committed
添加冒泡,选择,插入TS实现
1 parent ae0a61a commit ed6e44a

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

入门(Java)/经典算法TS实现.md

+41-6
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,55 @@
1313

1414
#### 选择排序
1515

16-
```java
17-
16+
```tsx
17+
const selectSort = function (nums: number[]) {
18+
const len = nums.length
19+
for (let i = 0; i < len; i++) {
20+
let min = i
21+
for (let j = i + 1; j < len; j++) {
22+
if (nums[j] < nums[min]) {
23+
min = j
24+
}
25+
}
26+
;[nums[i], nums[min]] = [nums[min], nums[i]]
27+
}
28+
return nums
29+
}
1830
```
1931

2032
#### 冒泡排序
2133

22-
```java
23-
34+
```tsx
35+
const bubbleSort = function (arrs: number[]) {
36+
const len = arrs.length
37+
let isSortFlag = false // 如果排好序只需遍历一遍
38+
for (let i = len - 1; i > 0 && !isSortFlag; i--) {
39+
isSortFlag = true
40+
for (let j = 0; j < i; j++) {
41+
if (arrs[j] > arrs[j + 1]) {
42+
isSortFlag = false
43+
;[arrs[j], arrs[j + 1]] = [arrs[j + 1], arrs[j]]
44+
}
45+
}
46+
}
47+
return arrs
48+
}
2449
```
2550

2651
#### 插入排序
2752

28-
```java
29-
53+
```tsx
54+
const insertSort = function (nums: number[]) {
55+
const len = nums.length
56+
for (let i = 1; i < len; i++) {
57+
for (let j = i; j > 0; j--) {
58+
if (nums[j] < nums[j - 1]) {
59+
;[nums[j], nums[j - 1]] = [nums[j - 1], nums[j]]
60+
}
61+
}
62+
}
63+
return nums
64+
}
3065
```
3166

3267
#### 希尔排序

论文/论文FaaSNet-ali.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FaaS平台最具吸引力的是资源弹性,允许用户程序在几秒内按
1616

1717
2.1 工作流
1818

19-
![](/Users/didi/Desktop/leetcode/论文/image/workflows.png)
19+
![](./image/workflows.png)
2020

2121
2.2 工作负载分析
2222

0 commit comments

Comments
 (0)