-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
412 lines (226 loc) · 288 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>君君教程网</title>
<subtitle>叶尼水的技术博客</subtitle>
<link href="/atom.xml" rel="self"/>
<link href="http://junjun.vip/"/>
<updated>2019-07-05T18:00:53.186Z</updated>
<id>http://junjun.vip/</id>
<author>
<name>JinXing Zhong</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>经典编程书籍大全</title>
<link href="http://junjun.vip/2019/07/06/%E7%BB%8F%E5%85%B8%E7%BC%96%E7%A8%8B%E4%B9%A6%E7%B1%8D%E5%A4%A7%E5%85%A8/"/>
<id>http://junjun.vip/2019/07/06/经典编程书籍大全/</id>
<published>2019-07-05T16:00:00.000Z</published>
<updated>2019-07-05T18:00:53.186Z</updated>
<content type="html"><![CDATA[<p>100+ 经典技术书籍,涵盖:计算机系统与网络、系统架构、算法与数据结构、前端开发、后端开发、移动开发、数据库、测试、项目与团队、程序员职业修炼、求职面试 和 编程相关的经典书籍。</p><h2 id="计算机系统与网络"><a href="#计算机系统与网络" class="headerlink" title="计算机系统与网络"></a>计算机系统与网络</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00AAQXKXS/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00AAQXKXS&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">图灵的秘密:他的生平、思想及论文解读</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0011F9OQE/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0011F9OQE&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">计算机系统概论</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0011F5RYM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0011F5RYM&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">深入理解Linux内核</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B003QN7J7U/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B003QN7J7U&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">深入Linux内核架构</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00116OTVS/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00116OTVS&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">TCP/IP详解 卷1:协议</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00JUM2ML4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00JUM2ML4&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Linux系统编程(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B004X3Z3D4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B004X3Z3D4&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Linux内核设计与实现(第3版)</a>》</li><li>《<a href="https://amazon.cn/gp/product/B01N03IQK4/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B01N03IQK4&linkId=b87deba0291c05df8d8ea0d64fefb0f0" target="_blank" rel="noopener">深入理解计算机系统(原书第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0011AP7RY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0011AP7RY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">计算机程序的构造和解释(原书第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B009RSXIB4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B009RSXIB4&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编码:隐匿在计算机软硬件背后的语言</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0140I5WPK/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0140I5WPK&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">性能之颠:洞悉系统、企业与云计算</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B011S72JB6/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B011S72JB6&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">UNIX网络编程 卷1:套接字联网API(第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B012R5A29O/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B012R5A29O&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">UNIX网络编程 卷2:进程间通信</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B001GS7918/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B001GS7918&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Windows核心编程(第5版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00PB5QQ84/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00PB5QQ84&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">WireShark网络分析就这么简单</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01AS1OS8A/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01AS1OS8A&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">WireShark网络分析的艺术</a>》</li></ul><h2 id="编程通用"><a href="#编程通用" class="headerlink" title="编程通用"></a>编程通用</h2><ul><li>《<a href="https://www.amazon.cn/dp/B00CD1EWMG/ref=sr_1_1?ie=UTF8&qid=1514903810&sr=8-1" target="_blank" rel="noopener">设计原本</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B006P7V73G/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B006P7V73G&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编程原本</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0061XKRXA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0061XKRXA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">代码大全</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B008Z1IEQ8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B008Z1IEQ8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">UNIX编程艺术</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0031M9GHC/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0031M9GHC&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">代码整洁之道</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00SFZH0DC/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00SFZH0DC&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编程珠玑(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0150BMQDM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0150BMQDM&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编程珠玑(续)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00IOAM6VE/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00IOAM6VE&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">软件调试的艺术</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00KMJ2Q1U/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00KMJ2Q1U&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">修改代码的艺术</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B007HYMPBY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B007HYMPBY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编程语言实现模式</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B008B4DTG4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B008B4DTG4&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编写可读代码的艺术</a>》</li><li>《解析极限编程:拥抱变化》</li><li>《<a href="https://www.amazon.cn/gp/product/B008UCHA58/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B008UCHA58&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">精通正则表达式(第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B001NGO85I/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B001NGO85I&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编译原理(第2版)</a>》龙书</li><li>《<a href="https://www.amazon.cn/gp/product/B011LPUB42/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B011LPUB42&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">重构:改善既有代码的设计</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00ALPRM3M/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00ALPRM3M&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">七周七语言:理解多种编程范型</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00CBBLUFK/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00CBBLUFK&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">调试九法:软硬件错误的排查之道</a>》</li><li>《程序设计语言:实践之路(第3版)》</li><li>《<a href="https://www.amazon.cn/gp/product/B00PG0MM3C/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00PG0MM3C&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">计算的本质:深入剖析程序和计算机</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B001130JN8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B001130JN8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">设计模式 : 可复用面向对象软件的基础</a>》</li><li>《<a href="https://amazon.cn/gp/product/B0011FBU34/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B0011FBU34&linkId=cd5d20e99ff289529d6dbe2cd223f2b6" target="_blank" rel="noopener">Head First 设计模式(中文版)</a> 》(感谢<a href="https://github.com/Great-Li-Xin" target="_blank" rel="noopener">@Great-Li-Xin</a> <a href="https://github.com/jobbole/awesome-programming-books/issues/27" target="_blank" rel="noopener">推荐</a> )</li></ul><h2 id="算法与数据结构"><a href="#算法与数据结构" class="headerlink" title="算法与数据结构"></a>算法与数据结构</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B009OCFQ0O/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B009OCFQ0O&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">算法(第4版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00AK7BYJY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00AK7BYJY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">算法导论(原书第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B019NB0VCI/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B019NB0VCI&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Python算法教程</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00S4HCQUI/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00S4HCQUI&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">算法设计与分析基础(第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B016DWSF8M/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B016DWSF8M&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">学习 JavaScript 数据结构与算法</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01LDG2DSG/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01LDG2DSG&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">数据结构与算法分析 : C++描述(第4版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B002WC7NGS/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B002WC7NGS&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">数据结构与算法分析 : C语言描述(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01CNP0CG6/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01CNP0CG6&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">数据结构与算法分析 : Java语言描述(第2版)</a>》</li></ul><h2 id="职业修炼与规划"><a href="#职业修炼与规划" class="headerlink" title="职业修炼与规划"></a>职业修炼与规划</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00KQDTZ4S/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00KQDTZ4S&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">大教堂与集市</a>》</li><li>《卓有成效的程序员》</li><li>《<a href="https://www.amazon.cn/gp/product/B01LZJ8L9J/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01LZJ8L9J&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">程序员的职业素养</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B004GV08CY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B004GV08CY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">程序员修炼之道:从小工到专家</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00H6X6LD4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00H6X6LD4&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">软件开发者路线图:从学徒到高手</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00CBBKDGM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00CBBKDGM&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">我编程,我快乐: 程序员职业规划之道</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B007VARUIM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B007VARUIM&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">程序员的思维修炼:开发认知潜能的九堂课</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00OA9L3NU/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00OA9L3NU&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">高效程序员的45个习惯:敏捷开发修炼之道(修订版)</a>》</li></ul><h2 id="大师访谈"><a href="#大师访谈" class="headerlink" title="大师访谈"></a>大师访谈</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00451BP72/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00451BP72&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编程大师智慧</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00ALPRKMA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00ALPRKMA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编程大师访谈录</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00QA7GA2Y/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00QA7GA2Y&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编程人生 : 15位软件先驱访谈录</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B007ED88CI/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B007ED88CI&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">奇思妙想 : 15位计算机天才及其重大发现</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B008G80O9K/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B008G80O9K&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">图灵和ACM图灵奖</a>》</li></ul><h2 id="架构-性能"><a href="#架构-性能" class="headerlink" title="架构/性能"></a>架构/性能</h2><ul><li>《<a href="https://www.amazon.cn/图书/dp/B01DXW29IM/ref=sr_1_1?s=books&ie=UTF8&qid=1496288348&sr=1-1" target="_blank" rel="noopener">架构即未来</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01ER75V6O/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01ER75V6O&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">微服务设计</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00NGW4EAG/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00NGW4EAG&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">大数据日知录</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B003LBSRDM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B003LBSRDM&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">企业应用架构模式</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00JMKWHFU/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00JMKWHFU&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Web性能权威指南</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01M0EHQ43/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01M0EHQ43&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">SRE:Google运维解密</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0153178XM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0153178XM&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">发布!软件的设计与部署</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01HZFHQQI/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01HZFHQQI&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">高扩展性网站的 50 条原则</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00F3Z26G8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00F3Z26G8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">大型网站技术架构:核心原理与案例分析</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00EP6TGAU/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00EP6TGAU&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">恰如其分的软件架构:风险驱动的设计方法</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00CMMUXC4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00CMMUXC4&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">软件系统架构:使用视点和视角与利益相关者合作(第2版)</a>》</li></ul><h2 id="Linux-Unix"><a href="#Linux-Unix" class="headerlink" title="Linux / Unix"></a>Linux / Unix</h2><ul><li>《<a href="https://amazon.cn/gp/product/B00HLA8TYG/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B00HLA8TYG&linkId=2d246600ae289155a09ec47545d584f6" target="_blank" rel="noopener">Linux/Unix 系统编程手册</a>》(感谢<a href="https://github.com/geekgao" target="_blank" rel="noopener">@geekgao</a> 的推荐)</li><li>《<a href="https://amazon.cn/gp/product/B00KMR129E/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B00KMR129E&linkId=9655c290f9d97c4d7e80093839cc5944" target="_blank" rel="noopener">Unix 环境高级编程(第3版)</a>》</li><li>《Unix/Linux 编程实践教程》</li><li>《<a href="https://amazon.cn/gp/product/B003TJNO98/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B003TJNO98&linkId=dda37757175b431dedc5e20212021f21" target="_blank" rel="noopener">鸟哥的 Linux 私房菜(基础学习篇)</a>》和《<a href="https://amazon.cn/gp/product/B008AEI8A2/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B008AEI8A2&linkId=35f878fbebb2f66ae8c4fc3e76914ff6" target="_blank" rel="noopener">鸟哥的 Linux 私房菜(服务器架设篇)</a>》</li><li>《<a href="https://amazon.cn/gp/product/B0719GT5W1/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B0719GT5W1&linkId=aeef8bc8651bd9e5f363527b86d1229a" target="_blank" rel="noopener">Linux 命令行与 shell 脚本编程大全(第3版)</a>》</li><li>《<a href="https://amazon.cn/gp/product/B00MB51SAI/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B00MB51SAI&linkId=b22fe2eaac93168eae25d9bab11fe30c" target="_blank" rel="noopener">只是为了好玩 : Linux 之父林纳斯自传</a>》</li></ul><h2 id="Web前端"><a href="#Web前端" class="headerlink" title="Web前端"></a>Web前端</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B013SGB2AO/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B013SGB2AO&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">高性能 JavaScript</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0089TDFNS/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0089TDFNS&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">锋利的 jQuery(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B016DWSEWO/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B016DWSEWO&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">JavaScript 忍者秘籍</a>》(感谢<a href="https://github.com/jobbole/awesome-programming-books/issues?q=is%3Aissue+is%3Aopen+author%3Ajoker-danta" target="_blank" rel="noopener">@joker-danta</a> 补充推荐)</li><li>《<a href="https://www.amazon.cn/gp/product/B00BQ7RMW0/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00BQ7RMW0&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编写可维护的 JavaScript</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00W34DZ8K/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00W34DZ8K&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">你不知道的 JavaScript(上)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01LMYXGAI/ref=pd_sim_14_1?ie=UTF8&psc=1&refRID=4JRMK10EFJQHDAG8MCZF" target="_blank" rel="noopener">你不知道的 JavaScript(中)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B007VISQ1Y/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B007VISQ1Y&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">JavaScript 权威指南(第6版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0097CON2S/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0097CON2S&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">JavaScript 语言精粹(修订版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B004VJM5KE/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B004VJM5KE&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">JavaScript DOM编程艺术 (第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B007OQQVMY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B007OQQVMY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">JavaScript 高级程序设计(第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00JVLEYY2/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00JVLEYY2&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">JavaScript 异步编程:设计快速响应的网络应用</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00XJ2AU3S/ref=pd_bxgy_14_img_3?ie=UTF8&psc=1&refRID=4JRMK10EFJQHDAG8MCZF" target="_blank" rel="noopener">JavaScript设计模式与开发实践</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B07574N7Y2/ref=pd_sim_14_7?ie=UTF8&psc=1&refRID=W48SJ7HFN2TXAQ1VAA8K" target="_blank" rel="noopener">JavaScript框架设计(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00GMXI1QY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00GMXI1QY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Effective JavaScript:编写高质量JavaScript代码的68个有效方法</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00H706BIG/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00H706BIG&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">HTML5 权威指南</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B015316VJY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B015316VJY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">HTML5 秘籍(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00K58535O/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00K58535O&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">HTML5 与 CSS3 基础教程(第八版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01ET3FO86/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01ET3FO86&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">CSS 揭秘</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00M2DKZ1W/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00M2DKZ1W&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">CSS 设计指南(第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0011F5SIC/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0011F5SIC&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">CSS 权威指南(第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01LXL42O5/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01LXL42O5&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">深入浅出 HTML 与 CSS</a>》</li><li>《<a href="https://www.amazon.cn/ES6%E6%A0%87%E5%87%86%E5%85%A5%E9%97%A8-%E9%98%AE%E4%B8%80%E5%B3%B0/dp/B0755547ZZ/ref=sr_1_3?s=books&ie=UTF8&qid=1510299626&sr=1-3&keywords=Ecmascript" target="_blank" rel="noopener">ES6 标准入门(第三版)</a>》</li><li>《<a href="https://www.amazon.cn/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3ES6-Nicholas-C-Zakas/dp/B071GW3JDP/ref=sr_1_1?s=books&ie=UTF8&qid=1510299626&sr=1-1&keywords=Ecmascript" target="_blank" rel="noopener">深入理解 ES6</a>》</li></ul><h2 id="Java开发"><a href="#Java开发" class="headerlink" title="Java开发"></a>Java开发</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B01ER75QC8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01ER75QC8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Java8 实战</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0077K9XHW/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0077K9XHW&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Java并发编程实战</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01DLB7Z66/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01DLB7Z66&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Java性能权威指南</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00E0D2OX4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00E0D2OX4&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Java程序员修炼之道</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B017MEN094/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B017MEN094&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">实战Java高并发程序设计</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0011F7WU4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0011F7WU4&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Java编程思想 (第4版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01HI0BUF8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01HI0BUF8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">深入理解Java虚拟机(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B001PTGR52/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B001PTGR52&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Effective java 中文版(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01M22BGUQ/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01M22BGUQ&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Java核心技术·卷1:基础知识(原书第9版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00IK7SM6O/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00IK7SM6O&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Java核心技术·卷2:高级特性(原书第9版)</a>》</li></ul><h2 id="NET-NET-Core"><a href="#NET-NET-Core" class="headerlink" title=".NET/.NET Core"></a>.NET/.NET Core</h2><ul><li>《<a href="https://www.amazon.cn/C-6-0%E6%9C%AC%E8%B4%A8%E8%AE%BA-%E9%A9%AC%E5%85%8B%C2%B7%E7%B1%B3%E5%87%AF%E5%88%A9%E6%96%AF/dp/B01N7U95UK/ref=sr_1_1?s=books&ie=UTF8&qid=1510299751&sr=1-1&keywords=C%23+%E6%9C%AC%E8%B4%A8%E8%AE%BA" target="_blank" rel="noopener">C# 6.0 本质论</a>》</li><li>《<a href="https://www.amazon.cn/%E6%9E%9C%E5%A3%B3%E4%B8%AD%E7%9A%84C-C-5-0%E6%9D%83%E5%A8%81%E6%8C%87%E5%8D%97-%E9%98%BF%E5%9D%9D%E5%93%88%E7%91%9E/dp/B00G51PUDA/ref=sr_1_1?s=books&ie=UTF8&qid=1510299796&sr=1-1&keywords=%E6%9E%9C%E5%A3%B3%E4%B8%AD%E7%9A%84C%23" target="_blank" rel="noopener">果壳中的C#:C#5.0权威指南</a>》</li><li>《你必须知道的.NET(第2版)》</li><li>《<a href="https://www.amazon.cn/gp/product/B00J94AG2A/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00J94AG2A&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">深入理解C#(第3版)</a>》</li><li>《Effective C#: 50 Specific Ways to Improve Your C#, Third Edition》</li><li>《More Effective C# (Includes Content Update Program): 50 Specific Ways to Improve Your C#, 2nd edition》</li><li>《<a href="https://www.amazon.cn/Async-in-C-5-0-Unleash-the-Power-of-Async-Davies-Alex/dp/1449337163/ref=sr_1_1?s=books&ie=UTF8&qid=1510299899&sr=1-1&keywords=Async+in+C%23+5.0" target="_blank" rel="noopener">Async in C# 5.0: Unleash the Power of Async</a>》</li><li>《<a href="https://www.amazon.cn/C-%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E7%BB%8F%E5%85%B8%E5%AE%9E%E4%BE%8B-%E5%85%8B%E5%88%A9%E9%87%8C/dp/B00QVLZEQ2/ref=sr_1_1?s=books&ie=UTF8&qid=1510299937&sr=1-1&keywords=C%23%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E7%BB%8F%E5%85%B8%E5%AE%9E%E4%BE%8B" target="_blank" rel="noopener">C#并发编程经典实例</a>》</li><li>《<a href="https://www.amazon.cn/C-%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BC%96%E7%A8%8B%E5%AE%9E%E6%88%98-%E6%98%93%E6%A0%BC%E6%81%A9%C2%B7%E9%98%BF%E6%A0%BC%E4%BD%9B%E6%B8%A9/dp/B06XHXV5FQ/ref=sr_1_1?s=books&ie=UTF8&qid=1510299974&sr=1-1&keywords=C%23%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BC%96%E7%A8%8B%E5%AE%9E%E6%88%98" target="_blank" rel="noopener">C#多线程编程实战(原书第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00P8VZ8T4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00P8VZ8T4&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">CLR via C#(第4版)</a>》</li><li>《.NET本质论 第1卷:公共语言运行库》</li><li>《.NET探秘 : MSIL权威指南》</li><li>《Pro .NET Performance》</li><li>《Shared Source CLI Essentials》</li><li>《.NET 高级调试》</li><li>《Microsoft.NET 和 Windows 应用程序调试》</li><li>《微软.NET 程序的加密与解密》</li><li>《<a href="https://www.amazon.cn/NET-Development-Using-the-Compiler-API-Bock-Jason/dp/1484221109/ref=sr_1_1?s=books&ie=UTF8&qid=1510300116&sr=1-1&keywords=.NET+Development+Using+the+Compiler+API" target="_blank" rel="noopener">.NET Development Using the Compiler API</a>》</li><li>《.NET设计规范 : 约定、惯用法与模式》</li><li>《<a href="https://www.amazon.cn/gp/product/B074JS9HWX/ref=pd_sim_14_9?ie=UTF8&psc=1&refRID=67XZ7GZVFZ3J57NQTJ8X" target="_blank" rel="noopener">编写高性能的.NET代码</a>》</li><li>《<a href="https://www.amazon.cn/Building-Microservices-with-NET-Core-Develop-skills-in-Reactive-Microservices-database-scaling-Azure-Microservices-and-more-Aroraa-Gaurav-Kumar/dp/B01MQ52RM3/ref=sr_1_10?s=books&ie=UTF8&qid=1510300439&sr=1-10&keywords=.net+core" target="_blank" rel="noopener">Building Microservices with .NET Core</a>》</li><li>《<a href="https://www.amazon.cn/Microservices-in-NET-Core-with-Examples-in-NancyFX-Horsdal-Christian/dp/1617293377/ref=sr_1_15?s=books&ie=UTF8&qid=1510300439&sr=1-15&keywords=.net+core" target="_blank" rel="noopener">Microservices in .NET Core, with Examples in NancyFX</a>》</li></ul><h2 id="Python"><a href="#Python" class="headerlink" title="Python"></a>Python</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00UI93JD8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00UI93JD8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">集体智慧编程</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00P6OJ0TC/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00P6OJ0TC&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">笨办法学Python</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00KAFX65Q/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00KAFX65Q&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Python基础教程</a>》</li><li>《Python源码剖析》</li><li>《<a href="https://www.amazon.cn/gp/product/B007NB2B4M/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B007NB2B4M&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Head First Python</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00HECW20S/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00HECW20S&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">与孩子一起学编程</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B004TUJ7A6/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B004TUJ7A6&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Python学习手册(第4版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00WKR1OKG/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00WKR1OKG&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Python Cookbook(第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01MCUN37Y/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01MCUN37Y&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Python参考手册(第4版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01FQAS0KK/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01FQAS0KK&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Python核心编程(第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01HCVUJFA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01HCVUJFA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Python科学计算(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00GHGZLWS/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00GHGZLWS&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">利用 Python 进行数据分析</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01ION3W54/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01ION3W54&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Think Python:像计算机科学家一样思考Python(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00MHDPIJ6/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00MHDPIJ6&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Python编程实战:运用设计模式、并发和程序库创建高质量程序</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B019ZRGBVU/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B019ZRGBVU&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Python绝技:运用Python成为顶级黑客</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0153177A6/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0153177A6&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Flask Web开发:基于Python的Web应用开发实战</a>》</li></ul><h2 id="Android"><a href="#Android" class="headerlink" title="Android"></a>Android</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B01FSXCBOQ/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01FSXCBOQ&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Android编程权威指南(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00SFZGX08/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00SFZGX08&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">移动应用UI设计模式(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/Android%E5%BC%80%E5%8F%91%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2-%E4%BB%BB%E7%8E%89%E5%88%9A/dp/B014HV1X3K/ref=sr_1_1?s=books&ie=UTF8&qid=1478155289&sr=1-1&keywords=android%E5%BC%80%E5%8F%91%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2" target="_blank" rel="noopener">Android开发艺术探索</a>》</li></ul><h2 id="iOS"><a href="#iOS" class="headerlink" title="iOS"></a>iOS</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00NKZCM3U/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00NKZCM3U&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">iOS编程实战</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B013UG2ULW/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B013UG2ULW&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">iOS编程(第4版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00DE60G3S/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00DE60G3S&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Objective-C高级编程</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00IDSGY06/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00IDSGY06&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Effective Objective-C 2.0:编写高质量iOS与OS X代码的52个有效方法</a>》</li></ul><h2 id="PHP"><a href="#PHP" class="headerlink" title="PHP"></a>PHP</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B004R1QIJU/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B004R1QIJU&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Head First PHP & MySQL(中文版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B005D6IRRY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B005D6IRRY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">深入PHP:面向对象、模式与实践(第3版)</a>》</li></ul><h2 id="C语言"><a href="#C语言" class="headerlink" title="C语言"></a>C语言</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00IZW4DK8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00IZW4DK8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C标准库</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00163LU68/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00163LU68&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C和指针</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0012NIW9K/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0012NIW9K&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C专家编程</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0012UMPBY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0012UMPBY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C陷阱与缺陷</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01D10NSCM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01D10NSCM&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C语言接口与实现</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0011425T8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0011425T8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C程序设计语言(第2版)</a>》</li><li>《C语言参考手册(第5版)》</li></ul><h2 id="C"><a href="#C" class="headerlink" title="C++"></a>C++</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00YLZIRHI/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00YLZIRHI&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C++标准库</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B005CFUQR0/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B005CFUQR0&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C++编程思想</a>》</li><li><span style="font-weight: normal;">《</span>C++语言的设计与演化<span style="font-weight: normal;">》</span></li><li>《<a href="https://www.amazon.cn/gp/product/B003VPX6YS/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B003VPX6YS&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C++程序设计原理与实践</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00ESUIL0O/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00ESUIL0O&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C++ Primer (中文第5版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00S6U4C6E/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00S6U4C6E&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C++ Primer习题集(第5版)</a> 》</li><li>《<a href="https://www.amazon.cn/gp/product/B01I9BNASA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01I9BNASA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">C++程序设计语言(第1-3部分)(原书第4版)</a> 》</li><li>《<a href="https://www.amazon.cn/gp/product/B004G72P24/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B004G72P24&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Effective C++:改善程序与设计的55个具体做法(第3版)(中文版) </a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B004IP8BD6/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B004IP8BD6&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">More Effective C++:35个改善编程与设计的有效方法(中文版) </a>》<br> </li></ul><h2 id="机器学习和数据挖掘"><a href="#机器学习和数据挖掘" class="headerlink" title="机器学习和数据挖掘"></a>机器学习和数据挖掘</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00JUE9DXW/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00JUE9DXW&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">数据之巅</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00NTM5GK0/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00NTM5GK0&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">矩阵分析</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B002WC7NH2/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B002WC7NH2&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">机器学习</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B007TSFMTA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B007TSFMTA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">统计学习方法</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B01AG3ZV9K/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B01AG3ZV9K&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">机器学习导论</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B008AK5YJO/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B008AK5YJO&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">推荐系统实践</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00D747PTK/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00D747PTK&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">机器学习实战</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00AY830HS/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00AY830HS&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Web数据挖掘</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B006PHIVNA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B006PHIVNA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">深入浅出统计学</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00116C3DY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00116C3DY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">模式分类(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00264GG56/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00264GG56&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">概率论与数理统计</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00PRH2BXA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00PRH2BXA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">统计学习基础(第2版)(英文)</a> 》</li><li>《<a href="https://www.amazon.cn/gp/product/B007NR0T4A/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B007NR0T4A&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">数据挖掘:概念与技术(第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00K5I91WK/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00K5I91WK&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">数据挖掘:实用机器学习工具与技术(原书第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B011I34CGA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B011I34CGA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">大数据:互联网大规模数据挖掘与分布式处理(第2版)</a>》</li></ul><h2 id="数据库"><a href="#数据库" class="headerlink" title="数据库"></a>数据库</h2><ul><li>《<a href="https://amazon.cn/gp/product/B007KYSEZC/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B007KYSEZC&linkId=32d1830aaeeda5b1ccaf242af94e73ad" target="_blank" rel="noopener">数据库系统概念</a>》 感谢<a href="https://github.com/noisnemid" target="_blank" rel="noopener">@noisnemid</a> <a href="https://github.com/jobbole/awesome-programming-books/issues/16" target="_blank" rel="noopener">推荐</a></li><li>《<a href="https://amazon.cn/gp/product/B003NX8D0A/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B003NX8D0A&linkId=3d1723a92384a5febb43c2400b31f1fe" target="_blank" rel="noopener">数据库系统实现</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00H6X6M1A/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00H6X6M1A&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">SQL应用重构</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/0596009763/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=0596009763&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">SQL Cookbook</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00C1W58DE/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00C1W58DE&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">高性能MySQL (第3版)</a>》</li><li>《深入浅出SQL(中文版)》</li><li>《<a href="https://www.amazon.cn/gp/product/B00ETOV48K/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00ETOV48K&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">MySQL技术内幕 : InnoDB存储引擎(第2版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00KR87J8G/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00KR87J8G&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">深入浅出MySQL : 数据库开发、优化与管理维护</a>》</li><li>《<a href="https://www.amazon.cn/%E6%94%B6%E8%8E%B7-%E4%B8%8D%E6%AD%A2SQL%E4%BC%98%E5%8C%96-%E6%8A%93%E4%BD%8FSQL%E7%9A%84%E6%9C%AC%E8%B4%A8-%E6%A2%81%E6%95%AC%E5%BD%AC/dp/B071S6ZYH8/ref=sr_1_1?s=books&ie=UTF8&qid=1510300270&sr=1-1&keywords=%E4%B8%8D%E6%AD%A2+sql" target="_blank" rel="noopener">收获,不止SQL优化:抓住SQL的本质</a>》</li><li>《<a href="https://www.amazon.cn/SQL-Server%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E4%B8%8E%E7%AE%A1%E7%90%86%E7%9A%84%E8%89%BA%E6%9C%AF-%E9%BB%84%E9%92%8A%E5%90%89/dp/B00NW2FVAM/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1510300294&sr=1-8" target="_blank" rel="noopener">SQL Server 性能优化与管理的艺术</a>》</li><li>《<a href="https://www.amazon.cn/SQL-Server%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98%E5%AE%9E%E6%88%98-%E9%99%88%E7%95%85%E4%BA%AE/dp/B0171JJEN6/ref=sr_1_11?s=books&ie=UTF8&qid=1510300294&sr=1-11&keywords=sql+server" target="_blank" rel="noopener">SQL Server性能调优实战</a>》</li><li>《<a href="https://www.amazon.cn/T-SQL%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98%E7%A7%98%E7%AC%88-%E5%9F%BA%E4%BA%8ESQL-Server-2012%E7%AA%97%E5%8F%A3%E5%87%BD%E6%95%B0-%E6%9C%AC-%E7%94%98/dp/B00M1CH5A8/ref=sr_1_14?s=books&ie=UTF8&qid=1510300294&sr=1-14&keywords=sql+server" target="_blank" rel="noopener">T-SQL性能调优秘笈:基于SQL Server 2012窗口函数</a>》</li></ul><h2 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B003JBIV0S/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B003JBIV0S&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">探索式软件测试</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00PVOND2W/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00PVOND2W&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">有效的单元测试</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00FH36R6G/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00FH36R6G&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">Google软件测试之道</a>》</li></ul><h2 id="项目与团队"><a href="#项目与团队" class="headerlink" title="项目与团队"></a>项目与团队</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00VR8ZO28/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00VR8ZO28&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">人月神话</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B001DBRWL0/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B001DBRWL0&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">快速软件开发</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00MO7R1SG/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00MO7R1SG&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">人件(原书第3版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00CBBKRQ8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00CBBKRQ8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">门后的秘密:卓越管理的故事</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00BLZMG8W/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00BLZMG8W&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">极客与团队:软件工程师的团队生存秘笈</a>》</li><li>《<a href="https://amazon.cn/gp/product/B00EE5HBAO/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=vastwork-23&creative=3200&linkCode=as2&creativeASIN=B00EE5HBAO&linkId=d904f054b7a79a701065f544a449512b" target="_blank" rel="noopener">硝烟中的 Scrum 和 XP</a>》 (感谢<a href="https://github.com/geekgao" target="_blank" rel="noopener">@geekgao</a> 的推荐。</li></ul><h2 id="求职面试"><a href="#求职面试" class="headerlink" title="求职面试"></a>求职面试</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B00G8VOQOG/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00G8VOQOG&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">程序员面试金典(第5版)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00W5269HO/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00W5269HO&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">编程之美 : 微软技术面试心得</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00ALPRM7S/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00ALPRM7S&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">金领简历:敲开苹果、微软、谷歌的大门</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00L5LKMVU/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00L5LKMVU&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">剑指Offer:名企面试官精讲典型编程题(纪念版)</a>》</li></ul><h2 id="编程之外"><a href="#编程之外" class="headerlink" title="编程之外"></a>编程之外</h2><ul><li>《<a href="https://www.amazon.cn/gp/product/B005DSK4W8/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B005DSK4W8&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">暗时间</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00P6OJ09C/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00P6OJ09C&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">数学之美</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00ANY9KZE/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00ANY9KZE&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">赢得朋友</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B008MIFWJG/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B008MIFWJG&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">精益创业</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00QPZARMA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00QPZARMA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">批判性思维</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00M2DKZNA/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00M2DKZNA&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">世界是数字的</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00A4H3JJS/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00A4H3JJS&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">程序员的数学</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00N4LZ6RO/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00N4LZ6RO&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">程序员健康指南</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B005O4PUFC/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B005O4PUFC&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">禅与摩托车维修艺术</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B0081M8TZ2/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B0081M8TZ2&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">关键对话:如何高效能沟通</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00EY8JUBO/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00EY8JUBO&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">写作法宝:非虚构写作指南</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00G1ZT2C0/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00G1ZT2C0&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">黑客与画家 : 来自计算机时代的高见</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00WDTQU8M/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00WDTQU8M&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">软件随想录(卷1)</a>》《<a href="https://www.amazon.cn/gp/product/B00WFT32FY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00WFT32FY&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">软件随想录(卷2)</a>》</li><li>《<a href="https://www.amazon.cn/gp/product/B00ICWNKT6/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=536&creative=3200&creativeASIN=B00ICWNKT6&linkCode=as2&tag=vastwork-23" target="_blank" rel="noopener">如何把事情做到最好:改变全球9800万人的人生指导书</a>》</li></ul>]]></content>
<summary type="html">
<p>100+ 经典技术书籍,涵盖:计算机系统与网络、系统架构、算法与数据结构、前端开发、后端开发、移动开发、数据库、测试、项目与团队、程序员职业修炼、求职面试 和 编程相关的经典书籍。</p>
<h2 id="计算机系统与网络"><a href="#计算机系统与网络" clas
</summary>
<category term="其他" scheme="http://junjun.vip/categories/%E5%85%B6%E4%BB%96/"/>
<category term="书籍" scheme="http://junjun.vip/tags/%E4%B9%A6%E7%B1%8D/"/>
</entry>
<entry>
<title>微信小程序4种常用的Flex布局模式</title>
<link href="http://junjun.vip/2019/07/06/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8FFlex%E5%B8%83%E5%B1%80/"/>
<id>http://junjun.vip/2019/07/06/微信小程序Flex布局/</id>
<published>2019-07-05T16:00:00.000Z</published>
<updated>2019-07-05T17:23:51.869Z</updated>
<content type="html"><![CDATA[<h2 id="官方建议的Flex布局"><a href="#官方建议的Flex布局" class="headerlink" title="官方建议的Flex布局"></a>官方建议的Flex布局</h2><blockquote><p>Flex的布局相比传统的float布局来说,简单、快捷、方便。掌握flex布局可以在制作微信小程序时减少wxss的代码,同时也符合微信小程序开发的文档要求</p></blockquote><p>本代码中涉及到四种Flex的布局方式,分别使用了不同的flex的不同属性。<br>建议看本文最后的学习参考进行相关属性的学习</p><h2 id="骰子布局"><a href="#骰子布局" class="headerlink" title="骰子布局"></a>骰子布局</h2><blockquote><p>骰子布局中主要强调几个属性的使用<code>display</code> <code>justify-content</code> <code>align-items</code> <code>align-self</code>等</p></blockquote><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">.first-face {</span><br><span class="line"> display: flex;</span><br><span class="line"> justify-content: center;</span><br><span class="line"> align-items: center;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">.second-face {</span><br><span class="line"> display: flex;</span><br><span class="line"> justify-content: space-between;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">.second-pip-2 {</span><br><span class="line"> align-self: flex-end;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><img src="/images/screenshot/shaizi.png" alt="骰子布局截图"></p><h2 id="网格布局"><a href="#网格布局" class="headerlink" title="网格布局"></a>网格布局</h2><blockquote><p>主要依赖flex属性</p></blockquote><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">.Grid {</span><br><span class="line"> display: flex;</span><br><span class="line">}</span><br><span class="line">.Grid-cell {</span><br><span class="line"> flex: 1;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><img src="/images/screenshot/grid.png" alt="网格布局截图"></p><h2 id="百分比布局"><a href="#百分比布局" class="headerlink" title="百分比布局"></a>百分比布局</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">.Grid {</span><br><span class="line"> display: flex;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">.cell-u-full {</span><br><span class="line"> flex: 0 0 100%;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><img src="/images/screenshot/perGrid.png" alt="百分比布局截图"></p><h2 id="流式布局"><a href="#流式布局" class="headerlink" title="流式布局"></a>流式布局</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">.parent {</span><br><span class="line"> width: 100%;</span><br><span class="line"> background-color: black;</span><br><span class="line"> display: flex;</span><br><span class="line"> flex-flow: row wrap;</span><br><span class="line"> align-content: flex-start;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">.child {</span><br><span class="line"> box-sizing: border-box;</span><br><span class="line"> background-color: white;</span><br><span class="line"> flex: 0 0 25%;</span><br><span class="line"> height: 50px;</span><br><span class="line"> border: 1px solid red;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><img src="/images/screenshot/stream.png" alt="流式布局截图"></p><h2 id="Flex-学习参考"><a href="#Flex-学习参考" class="headerlink" title="Flex 学习参考"></a>Flex 学习参考</h2><ul><li><p>本代码参考<a href="http://www.ruanyifeng.com/blog/2015/07/flex-examples.html" target="_blank" rel="noopener">阮一峰的网络日志:Flex 布局教程:实例篇</a>编写</p></li><li><p>语法学习 <a href="http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html" target="_blank" rel="noopener">阮一峰的网络日志:Flex 布局教程:语法篇</a></p></li></ul>]]></content>
<summary type="html">
<h2 id="官方建议的Flex布局"><a href="#官方建议的Flex布局" class="headerlink" title="官方建议的Flex布局"></a>官方建议的Flex布局</h2><blockquote>
<p>Flex的布局相比传统的float布局来说
</summary>
<category term="小程序" scheme="http://junjun.vip/categories/%E5%B0%8F%E7%A8%8B%E5%BA%8F/"/>
<category term="flex布局" scheme="http://junjun.vip/tags/flex%E5%B8%83%E5%B1%80/"/>
</entry>
<entry>
<title>插入排序</title>
<link href="http://junjun.vip/2019/07/05/3.insertionSort/"/>
<id>http://junjun.vip/2019/07/05/3.insertionSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:32:54.039Z</updated>
<content type="html"><![CDATA[<p>插入排序的代码实现虽然没有冒泡排序和选择排序那么简单粗暴,但它的原理应该是最容易理解的了,因为只要打过扑克牌的人都应该能够秒懂。插入排序是一种最简单直观的排序算法,它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。</p><p>插入排序和冒泡排序一样,也有一种优化算法,叫做拆半插入。</p><h2 id="1-算法步骤"><a href="#1-算法步骤" class="headerlink" title="1. 算法步骤"></a>1. 算法步骤</h2><ol><li><p>将第一待排序序列第一个元素看做一个有序序列,把第二个元素到最后一个元素当成是未排序序列。</p></li><li><p>从头到尾依次扫描未排序序列,将扫描到的每个元素插入有序序列的适当位置。(如果待插入的元素与有序序列中的某个元素相等,则将待插入元素插入到相等元素的后面。)</p></li></ol><h2 id="2-动图演示"><a href="#2-动图演示" class="headerlink" title="2. 动图演示"></a>2. 动图演示</h2><p><img src="/images/sort/insertionSort.gif" alt="动图演示"></p><h2 id="3-JavaScript-代码实现"><a href="#3-JavaScript-代码实现" class="headerlink" title="3. JavaScript 代码实现"></a>3. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">insertionSort</span>(<span class="params">arr</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> len = arr.length;</span><br><span class="line"> <span class="keyword">var</span> preIndex, current;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">1</span>; i < len; i++) {</span><br><span class="line"> preIndex = i - <span class="number">1</span>;</span><br><span class="line"> current = arr[i];</span><br><span class="line"> <span class="keyword">while</span>(preIndex >= <span class="number">0</span> && arr[preIndex] > current) {</span><br><span class="line"> arr[preIndex+<span class="number">1</span>] = arr[preIndex];</span><br><span class="line"> preIndex--;</span><br><span class="line"> }</span><br><span class="line"> arr[preIndex+<span class="number">1</span>] = current;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="4-Python-代码实现"><a href="#4-Python-代码实现" class="headerlink" title="4. Python 代码实现"></a>4. Python 代码实现</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">insertionSort</span><span class="params">(arr)</span>:</span></span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(len(arr)):</span><br><span class="line"> preIndex = i<span class="number">-1</span></span><br><span class="line"> current = arr[i]</span><br><span class="line"> <span class="keyword">while</span> preIndex >= <span class="number">0</span> <span class="keyword">and</span> arr[preIndex] > current:</span><br><span class="line"> arr[preIndex+<span class="number">1</span>] = arr[preIndex]</span><br><span class="line"> preIndex-=<span class="number">1</span></span><br><span class="line"> arr[preIndex+<span class="number">1</span>] = current</span><br><span class="line"> <span class="keyword">return</span> arr</span><br></pre></td></tr></table></figure><h2 id="5-Go-代码实现"><a href="#5-Go-代码实现" class="headerlink" title="5. Go 代码实现"></a>5. Go 代码实现</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">insertionSort</span><span class="params">(arr []<span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line"><span class="keyword">for</span> i := <span class="keyword">range</span> arr {</span><br><span class="line">preIndex := i - <span class="number">1</span></span><br><span class="line">current := arr[i]</span><br><span class="line"><span class="keyword">for</span> preIndex >= <span class="number">0</span> && arr[preIndex] > current {</span><br><span class="line">arr[preIndex+<span class="number">1</span>] = arr[preIndex]</span><br><span class="line">preIndex -= <span class="number">1</span></span><br><span class="line">}</span><br><span class="line">arr[preIndex+<span class="number">1</span>] = current</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> arr</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="6-Java-代码实现"><a href="#6-Java-代码实现" class="headerlink" title="6. Java 代码实现"></a>6. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">InsertSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="comment">// 对 arr 进行拷贝,不改变参数内容</span></span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 从下标为1的元素开始选择合适的位置插入,因为下标为0的只有一个元素,默认是有序的</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i < arr.length; i++) {</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 记录要插入的数据</span></span><br><span class="line"> <span class="keyword">int</span> tmp = arr[i];</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 从已经排序的序列最右边的开始比较,找到比其小的数</span></span><br><span class="line"> <span class="keyword">int</span> j = i;</span><br><span class="line"> <span class="keyword">while</span> (j > <span class="number">0</span> && tmp < arr[j - <span class="number">1</span>]) {</span><br><span class="line"> arr[j] = arr[j - <span class="number">1</span>];</span><br><span class="line"> j--;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 存在比其小的数,插入</span></span><br><span class="line"> <span class="keyword">if</span> (j != i) {</span><br><span class="line"> arr[j] = tmp;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="7-PHP-代码实现"><a href="#7-PHP-代码实现" class="headerlink" title="7. PHP 代码实现"></a>7. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">insertionSort</span><span class="params">($arr)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> $len = count($arr);</span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">1</span>; $i < $len; $i++) {</span><br><span class="line"> $preIndex = $i - <span class="number">1</span>;</span><br><span class="line"> $current = $arr[$i];</span><br><span class="line"> <span class="keyword">while</span>($preIndex >= <span class="number">0</span> && $arr[$preIndex] > $current) {</span><br><span class="line"> $arr[$preIndex+<span class="number">1</span>] = $arr[$preIndex];</span><br><span class="line"> $preIndex--;</span><br><span class="line"> }</span><br><span class="line"> $arr[$preIndex+<span class="number">1</span>] = $current;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>插入排序的代码实现虽然没有冒泡排序和选择排序那么简单粗暴,但它的原理应该是最容易理解的了,因为只要打过扑克牌的人都应该能够秒懂。插入排序是一种最简单直观的排序算法,它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。</p>
<p
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>冒泡排序</title>
<link href="http://junjun.vip/2019/07/05/1.bubbleSort/"/>
<id>http://junjun.vip/2019/07/05/1.bubbleSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:32:46.034Z</updated>
<content type="html"><![CDATA[<p>冒泡排序(Bubble Sort)也是一种简单直观的排序算法。它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来。走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成。这个算法的名字由来是因为越小的元素会经由交换慢慢“浮”到数列的顶端。</p><p>作为最简单的排序算法之一,冒泡排序给我的感觉就像 Abandon 在单词书里出现的感觉一样,每次都在第一页第一位,所以最熟悉。冒泡排序还有一种优化算法,就是立一个 flag,当在一趟序列遍历中元素没有发生交换,则证明该序列已经有序。但这种改进对于提升性能来说并没有什么太大作用。</p><h2 id="1-算法步骤"><a href="#1-算法步骤" class="headerlink" title="1. 算法步骤"></a>1. 算法步骤</h2><ol><li><p>比较相邻的元素。如果第一个比第二个大,就交换他们两个。</p></li><li><p>对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。这步做完后,最后的元素会是最大的数。</p></li><li><p>针对所有的元素重复以上的步骤,除了最后一个。</p></li><li><p>持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需要比较。</p></li></ol><h2 id="2-动图演示"><a href="#2-动图演示" class="headerlink" title="2. 动图演示"></a>2. 动图演示</h2><p>![动图演示]/images/sort/bubbleSort.gif)</p><h2 id="3-什么时候最快"><a href="#3-什么时候最快" class="headerlink" title="3. 什么时候最快"></a>3. 什么时候最快</h2><p>当输入的数据已经是正序时(都已经是正序了,我还要你冒泡排序有何用啊)。</p><h2 id="4-什么时候最慢"><a href="#4-什么时候最慢" class="headerlink" title="4. 什么时候最慢"></a>4. 什么时候最慢</h2><p>当输入的数据是反序时(写一个 for 循环反序输出数据不就行了,干嘛要用你冒泡排序呢,我是闲的吗)。</p><h2 id="5-JavaScript-代码实现"><a href="#5-JavaScript-代码实现" class="headerlink" title="5. JavaScript 代码实现"></a>5. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">bubbleSort</span>(<span class="params">arr</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> len = arr.length;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i < len - <span class="number">1</span>; i++) {</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> j = <span class="number">0</span>; j < len - <span class="number">1</span> - i; j++) {</span><br><span class="line"> <span class="keyword">if</span> (arr[j] > arr[j+<span class="number">1</span>]) { <span class="comment">// 相邻元素两两对比</span></span><br><span class="line"> <span class="keyword">var</span> temp = arr[j+<span class="number">1</span>]; <span class="comment">// 元素交换</span></span><br><span class="line"> arr[j+<span class="number">1</span>] = arr[j];</span><br><span class="line"> arr[j] = temp;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="6-Python-代码实现"><a href="#6-Python-代码实现" class="headerlink" title="6. Python 代码实现"></a>6. Python 代码实现</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">bubbleSort</span><span class="params">(arr)</span>:</span></span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1</span>, len(arr)):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> range(<span class="number">0</span>, len(arr)-i):</span><br><span class="line"> <span class="keyword">if</span> arr[j] > arr[j+<span class="number">1</span>]:</span><br><span class="line"> arr[j], arr[j + <span class="number">1</span>] = arr[j + <span class="number">1</span>], arr[j]</span><br><span class="line"> <span class="keyword">return</span> arr</span><br></pre></td></tr></table></figure><h2 id="7-Go-代码实现"><a href="#7-Go-代码实现" class="headerlink" title="7. Go 代码实现"></a>7. Go 代码实现</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">bubbleSort</span><span class="params">(arr []<span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line">length := <span class="built_in">len</span>(arr)</span><br><span class="line"><span class="keyword">for</span> i := <span class="number">0</span>; i < length; i++ {</span><br><span class="line"><span class="keyword">for</span> j := <span class="number">0</span>; j < length<span class="number">-1</span>-i; j++ {</span><br><span class="line"><span class="keyword">if</span> arr[j] > arr[j+<span class="number">1</span>] {</span><br><span class="line">arr[j], arr[j+<span class="number">1</span>] = arr[j+<span class="number">1</span>], arr[j]</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> arr</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="8-Java-代码实现"><a href="#8-Java-代码实现" class="headerlink" title="8. Java 代码实现"></a>8. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BubbleSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="comment">// 对 arr 进行拷贝,不改变参数内容</span></span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i < arr.length; i++) {</span><br><span class="line"> <span class="comment">// 设定一个标记,若为true,则表示此次循环没有进行交换,也就是待排序列已经有序,排序已经完成。</span></span><br><span class="line"> <span class="keyword">boolean</span> flag = <span class="keyword">true</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j < arr.length - i; j++) {</span><br><span class="line"> <span class="keyword">if</span> (arr[j] > arr[j + <span class="number">1</span>]) {</span><br><span class="line"> <span class="keyword">int</span> tmp = arr[j];</span><br><span class="line"> arr[j] = arr[j + <span class="number">1</span>];</span><br><span class="line"> arr[j + <span class="number">1</span>] = tmp;</span><br><span class="line"></span><br><span class="line"> flag = <span class="keyword">false</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (flag) {</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="9-PHP-代码实现"><a href="#9-PHP-代码实现" class="headerlink" title="9. PHP 代码实现"></a>9. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">bubbleSort</span><span class="params">($arr)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> $len = count($arr);</span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">0</span>; $i < $len - <span class="number">1</span>; $i++) {</span><br><span class="line"> <span class="keyword">for</span> ($j = <span class="number">0</span>; $j < $len - <span class="number">1</span> - $i; $j++) {</span><br><span class="line"> <span class="keyword">if</span> ($arr[$j] > $arr[$j+<span class="number">1</span>]) {</span><br><span class="line"> $tmp = $arr[$j];</span><br><span class="line"> $arr[$j] = $arr[$j+<span class="number">1</span>];</span><br><span class="line"> $arr[$j+<span class="number">1</span>] = $tmp;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>冒泡排序(Bubble Sort)也是一种简单直观的排序算法。它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来。走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成。这个算法的名字由来是因为越小的元素会经由交换慢慢“浮”到
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>基数排序</title>
<link href="http://junjun.vip/2019/07/05/10.radixSort/"/>
<id>http://junjun.vip/2019/07/05/10.radixSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:33:23.451Z</updated>
<content type="html"><![CDATA[<p>基数排序是一种非比较型整数排序算法,其原理是将整数按位数切割成不同的数字,然后按每个位数分别比较。由于整数也可以表达字符串(比如名字或日期)和特定格式的浮点数,所以基数排序也不是只能使用于整数。</p><h2 id="1-基数排序-vs-计数排序-vs-桶排序"><a href="#1-基数排序-vs-计数排序-vs-桶排序" class="headerlink" title="1. 基数排序 vs 计数排序 vs 桶排序"></a>1. 基数排序 vs 计数排序 vs 桶排序</h2><p>基数排序有两种方法:</p><p>这三种排序算法都利用了桶的概念,但对桶的使用方法上有明显差异:</p><ul><li>基数排序:根据键值的每位数字来分配桶;</li><li>计数排序:每个桶只存储单一键值;</li><li>桶排序:每个桶存储一定范围的数值;</li></ul><h2 id="2-LSD-基数排序动图演示"><a href="#2-LSD-基数排序动图演示" class="headerlink" title="2. LSD 基数排序动图演示"></a>2. LSD 基数排序动图演示</h2><p><img src="/images/sort/radixSort.gif" alt="动图演示"></p><h2 id="3-JavaScript-代码实现"><a href="#3-JavaScript-代码实现" class="headerlink" title="3. JavaScript 代码实现"></a>3. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//LSD Radix Sort</span></span><br><span class="line"><span class="keyword">var</span> counter = [];</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">radixSort</span>(<span class="params">arr, maxDigit</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> mod = <span class="number">10</span>;</span><br><span class="line"> <span class="keyword">var</span> dev = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i < maxDigit; i++, dev *= <span class="number">10</span>, mod *= <span class="number">10</span>) {</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">var</span> j = <span class="number">0</span>; j < arr.length; j++) {</span><br><span class="line"> <span class="keyword">var</span> bucket = <span class="built_in">parseInt</span>((arr[j] % mod) / dev);</span><br><span class="line"> <span class="keyword">if</span>(counter[bucket]==<span class="literal">null</span>) {</span><br><span class="line"> counter[bucket] = [];</span><br><span class="line"> }</span><br><span class="line"> counter[bucket].push(arr[j]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">var</span> pos = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">var</span> j = <span class="number">0</span>; j < counter.length; j++) {</span><br><span class="line"> <span class="keyword">var</span> value = <span class="literal">null</span>;</span><br><span class="line"> <span class="keyword">if</span>(counter[j]!=<span class="literal">null</span>) {</span><br><span class="line"> <span class="keyword">while</span> ((value = counter[j].shift()) != <span class="literal">null</span>) {</span><br><span class="line"> arr[pos++] = value;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="4-Java-代码实现"><a href="#4-Java-代码实现" class="headerlink" title="4. Java 代码实现"></a>4. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 基数排序</span></span><br><span class="line"><span class="comment"> * 考虑负数的情况还可以参考: https://code.i-harness.com/zh-CN/q/e98fa9</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RadixSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="comment">// 对 arr 进行拷贝,不改变参数内容</span></span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> maxDigit = getMaxDigit(arr);</span><br><span class="line"> <span class="keyword">return</span> radixSort(arr, maxDigit);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取最高位数</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">getMaxDigit</span><span class="params">(<span class="keyword">int</span>[] arr)</span> </span>{</span><br><span class="line"> <span class="keyword">int</span> maxValue = getMaxValue(arr);</span><br><span class="line"> <span class="keyword">return</span> getNumLenght(maxValue);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">getMaxValue</span><span class="params">(<span class="keyword">int</span>[] arr)</span> </span>{</span><br><span class="line"> <span class="keyword">int</span> maxValue = arr[<span class="number">0</span>];</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> value : arr) {</span><br><span class="line"> <span class="keyword">if</span> (maxValue < value) {</span><br><span class="line"> maxValue = value;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> maxValue;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">protected</span> <span class="keyword">int</span> <span class="title">getNumLenght</span><span class="params">(<span class="keyword">long</span> num)</span> </span>{</span><br><span class="line"> <span class="keyword">if</span> (num == <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> lenght = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">long</span> temp = num; temp != <span class="number">0</span>; temp /= <span class="number">10</span>) {</span><br><span class="line"> lenght++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> lenght;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">int</span>[] radixSort(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> maxDigit) {</span><br><span class="line"> <span class="keyword">int</span> mod = <span class="number">10</span>;</span><br><span class="line"> <span class="keyword">int</span> dev = <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i < maxDigit; i++, dev *= <span class="number">10</span>, mod *= <span class="number">10</span>) {</span><br><span class="line"> <span class="comment">// 考虑负数的情况,这里扩展一倍队列数,其中 [0-9]对应负数,[10-19]对应正数 (bucket + 10)</span></span><br><span class="line"> <span class="keyword">int</span>[][] counter = <span class="keyword">new</span> <span class="keyword">int</span>[mod * <span class="number">2</span>][<span class="number">0</span>];</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j < arr.length; j++) {</span><br><span class="line"> <span class="keyword">int</span> bucket = ((arr[j] % mod) / dev) + mod;</span><br><span class="line"> counter[bucket] = arrayAppend(counter[bucket], arr[j]);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> pos = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span>[] bucket : counter) {</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> value : bucket) {</span><br><span class="line"> arr[pos++] = value;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 自动扩容,并保存数据</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> arr</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> value</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">int</span>[] arrayAppend(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> value) {</span><br><span class="line"> arr = Arrays.copyOf(arr, arr.length + <span class="number">1</span>);</span><br><span class="line"> arr[arr.length - <span class="number">1</span>] = value;</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="5-PHP-代码实现"><a href="#5-PHP-代码实现" class="headerlink" title="5. PHP 代码实现"></a>5. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">radixSort</span><span class="params">($arr, $maxDigit = null)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span> ($maxDigit === <span class="keyword">null</span>) {</span><br><span class="line"> $maxDigit = max($arr);</span><br><span class="line"> }</span><br><span class="line"> $counter = [];</span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">0</span>; $i < $maxDigit; $i++) {</span><br><span class="line"> <span class="keyword">for</span> ($j = <span class="number">0</span>; $j < count($arr); $j++) {</span><br><span class="line"> preg_match_all(<span class="string">'/\d/'</span>, (string) $arr[$j], $matches);</span><br><span class="line"> $numArr = $matches[<span class="number">0</span>];</span><br><span class="line"> $lenTmp = count($numArr);</span><br><span class="line"> $bucket = array_key_exists($lenTmp - $i - <span class="number">1</span>, $numArr)</span><br><span class="line"> ? intval($numArr[$lenTmp - $i - <span class="number">1</span>])</span><br><span class="line"> : <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span> (!array_key_exists($bucket, $counter)) {</span><br><span class="line"> $counter[$bucket] = [];</span><br><span class="line"> }</span><br><span class="line"> $counter[$bucket][] = $arr[$j];</span><br><span class="line"> }</span><br><span class="line"> $pos = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> ($j = <span class="number">0</span>; $j < count($counter); $j++) {</span><br><span class="line"> $value = <span class="keyword">null</span>;</span><br><span class="line"> <span class="keyword">if</span> ($counter[$j] !== <span class="keyword">null</span>) {</span><br><span class="line"> <span class="keyword">while</span> (($value = array_shift($counter[$j])) !== <span class="keyword">null</span>) {</span><br><span class="line"> $arr[$pos++] = $value;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>基数排序是一种非比较型整数排序算法,其原理是将整数按位数切割成不同的数字,然后按每个位数分别比较。由于整数也可以表达字符串(比如名字或日期)和特定格式的浮点数,所以基数排序也不是只能使用于整数。</p>
<h2 id="1-基数排序-vs-计数排序-vs-桶排序"><a h
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>选择排序</title>
<link href="http://junjun.vip/2019/07/05/2.selectionSort/"/>
<id>http://junjun.vip/2019/07/05/2.selectionSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:32:50.333Z</updated>
<content type="html"><![CDATA[<p>选择排序是一种简单直观的排序算法,无论什么数据进去都是 O(n²) 的时间复杂度。所以用到它的时候,数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。</p><h2 id="1-算法步骤"><a href="#1-算法步骤" class="headerlink" title="1. 算法步骤"></a>1. 算法步骤</h2><ol><li><p>首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置</p></li><li><p>再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾。</p></li><li><p>重复第二步,直到所有元素均排序完毕。</p></li></ol><h2 id="2-动图演示"><a href="#2-动图演示" class="headerlink" title="2. 动图演示"></a>2. 动图演示</h2><p><img src="/images/sort/selectionSort.gif" alt="动图演示"></p><h2 id="3-JavaScript-代码实现"><a href="#3-JavaScript-代码实现" class="headerlink" title="3. JavaScript 代码实现"></a>3. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">selectionSort</span>(<span class="params">arr</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> len = arr.length;</span><br><span class="line"> <span class="keyword">var</span> minIndex, temp;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i < len - <span class="number">1</span>; i++) {</span><br><span class="line"> minIndex = i;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> j = i + <span class="number">1</span>; j < len; j++) {</span><br><span class="line"> <span class="keyword">if</span> (arr[j] < arr[minIndex]) { <span class="comment">// 寻找最小的数</span></span><br><span class="line"> minIndex = j; <span class="comment">// 将最小数的索引保存</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> temp = arr[i];</span><br><span class="line"> arr[i] = arr[minIndex];</span><br><span class="line"> arr[minIndex] = temp;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="4-Python-代码实现"><a href="#4-Python-代码实现" class="headerlink" title="4. Python 代码实现"></a>4. Python 代码实现</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">selectionSort</span><span class="params">(arr)</span>:</span></span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(len(arr) - <span class="number">1</span>):</span><br><span class="line"> <span class="comment"># 记录最小数的索引</span></span><br><span class="line"> minIndex = i</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> range(i + <span class="number">1</span>, len(arr)):</span><br><span class="line"> <span class="keyword">if</span> arr[j] < arr[minIndex]:</span><br><span class="line"> minIndex = j</span><br><span class="line"> <span class="comment"># i 不是最小数时,将 i 和最小数进行交换</span></span><br><span class="line"> <span class="keyword">if</span> i != minIndex:</span><br><span class="line"> arr[i], arr[minIndex] = arr[minIndex], arr[i]</span><br><span class="line"> <span class="keyword">return</span> arr</span><br></pre></td></tr></table></figure><h2 id="5-Go-代码实现"><a href="#5-Go-代码实现" class="headerlink" title="5. Go 代码实现"></a>5. Go 代码实现</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">selectionSort</span><span class="params">(arr []<span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line">length := <span class="built_in">len</span>(arr)</span><br><span class="line"><span class="keyword">for</span> i := <span class="number">0</span>; i < length<span class="number">-1</span>; i++ {</span><br><span class="line">min := i</span><br><span class="line"><span class="keyword">for</span> j := i + <span class="number">1</span>; j < length; j++ {</span><br><span class="line"><span class="keyword">if</span> arr[min] > arr[j] {</span><br><span class="line">min = j</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">arr[i], arr[min] = arr[min], arr[i]</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> arr</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="6-Java-代码实现"><a href="#6-Java-代码实现" class="headerlink" title="6. Java 代码实现"></a>6. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SelectionSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 总共要经过 N-1 轮比较</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i < arr.length - <span class="number">1</span>; i++) {</span><br><span class="line"> <span class="keyword">int</span> min = i;</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 每轮需要比较的次数 N-i</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> j = i + <span class="number">1</span>; j < arr.length; j++) {</span><br><span class="line"> <span class="keyword">if</span> (arr[j] < arr[min]) {</span><br><span class="line"> <span class="comment">// 记录目前能找到的最小值元素的下标</span></span><br><span class="line"> min = j;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 将找到的最小值和i位置所在的值进行交换</span></span><br><span class="line"> <span class="keyword">if</span> (i != min) {</span><br><span class="line"> <span class="keyword">int</span> tmp = arr[i];</span><br><span class="line"> arr[i] = arr[min];</span><br><span class="line"> arr[min] = tmp;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="7-PHP-代码实现"><a href="#7-PHP-代码实现" class="headerlink" title="7. PHP 代码实现"></a>7. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">selectionSort</span><span class="params">($arr)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> $len = count($arr);</span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">0</span>; $i < $len - <span class="number">1</span>; $i++) {</span><br><span class="line"> $minIndex = $i;</span><br><span class="line"> <span class="keyword">for</span> ($j = $i + <span class="number">1</span>; $j < $len; $j++) {</span><br><span class="line"> <span class="keyword">if</span> ($arr[$j] < $arr[$minIndex]) {</span><br><span class="line"> $minIndex = $j;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> $temp = $arr[$i];</span><br><span class="line"> $arr[$i] = $arr[$minIndex];</span><br><span class="line"> $arr[$minIndex] = $temp;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>选择排序是一种简单直观的排序算法,无论什么数据进去都是 O(n²) 的时间复杂度。所以用到它的时候,数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。</p>
<h2 id="1-算法步骤"><a href="#1-算法步骤" class="headerlink
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>希尔排序</title>
<link href="http://junjun.vip/2019/07/05/4.shellSort/"/>
<id>http://junjun.vip/2019/07/05/4.shellSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:32:59.542Z</updated>
<content type="html"><![CDATA[<p>希尔排序,也称递减增量排序算法,是插入排序的一种更高效的改进版本。但希尔排序是非稳定排序算法。</p><p>希尔排序是基于插入排序的以下两点性质而提出改进方法的:</p><ul><li>插入排序在对几乎已经排好序的数据操作时,效率高,即可以达到线性排序的效率;</li><li>但插入排序一般来说是低效的,因为插入排序每次只能将数据移动一位;</li></ul><p>希尔排序的基本思想是:先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录“基本有序”时,再对全体记录进行依次直接插入排序。</p><h2 id="1-算法步骤"><a href="#1-算法步骤" class="headerlink" title="1. 算法步骤"></a>1. 算法步骤</h2><ol><li><p>选择一个增量序列 t1,t2,……,tk,其中 ti > tj, tk = 1;</p></li><li><p>按增量序列个数 k,对序列进行 k 趟排序;</p></li><li><p>每趟排序,根据对应的增量 ti,将待排序列分割成若干长度为 m 的子序列,分别对各子表进行直接插入排序。仅增量因子为 1 时,整个序列作为一个表来处理,表长度即为整个序列的长度。</p></li></ol><h2 id="2-JavaScript-代码实现"><a href="#2-JavaScript-代码实现" class="headerlink" title="2. JavaScript 代码实现"></a>2. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">shellSort</span>(<span class="params">arr</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> len = arr.length,</span><br><span class="line"> temp,</span><br><span class="line"> gap = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span>(gap < len/<span class="number">3</span>) { <span class="comment">//动态定义间隔序列</span></span><br><span class="line"> gap =gap*<span class="number">3</span>+<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span> (gap; gap > <span class="number">0</span>; gap = <span class="built_in">Math</span>.floor(gap/<span class="number">3</span>)) {</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = gap; i < len; i++) {</span><br><span class="line"> temp = arr[i];</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> j = i-gap; j >= <span class="number">0</span> && arr[j] > temp; j-=gap) {</span><br><span class="line"> arr[j+gap] = arr[j];</span><br><span class="line"> }</span><br><span class="line"> arr[j+gap] = temp;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="3-Python-代码实现"><a href="#3-Python-代码实现" class="headerlink" title="3. Python 代码实现"></a>3. Python 代码实现</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">shellSort</span><span class="params">(arr)</span>:</span></span><br><span class="line"> <span class="keyword">import</span> math</span><br><span class="line"> gap=<span class="number">1</span></span><br><span class="line"> <span class="keyword">while</span>(gap < len(arr)/<span class="number">3</span>):</span><br><span class="line"> gap = gap*<span class="number">3</span>+<span class="number">1</span></span><br><span class="line"> <span class="keyword">while</span> gap > <span class="number">0</span>:</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(gap,len(arr)):</span><br><span class="line"> temp = arr[i]</span><br><span class="line"> j = i-gap</span><br><span class="line"> <span class="keyword">while</span> j >=<span class="number">0</span> <span class="keyword">and</span> arr[j] > temp:</span><br><span class="line"> arr[j+gap]=arr[j]</span><br><span class="line"> j-=gap</span><br><span class="line"> arr[j+gap] = temp</span><br><span class="line"> gap = math.floor(gap/<span class="number">3</span>)</span><br><span class="line"> <span class="keyword">return</span> arr</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="4-Go-代码实现"><a href="#4-Go-代码实现" class="headerlink" title="4. Go 代码实现"></a>4. Go 代码实现</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">shellSort</span><span class="params">(arr []<span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line">length := <span class="built_in">len</span>(arr)</span><br><span class="line">gap := <span class="number">1</span></span><br><span class="line"><span class="keyword">for</span> gap < gap/<span class="number">3</span> {</span><br><span class="line">gap = gap*<span class="number">3</span> + <span class="number">1</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">for</span> gap > <span class="number">0</span> {</span><br><span class="line"><span class="keyword">for</span> i := gap; i < length; i++ {</span><br><span class="line">temp := arr[i]</span><br><span class="line">j := i - gap</span><br><span class="line"><span class="keyword">for</span> j >= <span class="number">0</span> && arr[j] > temp {</span><br><span class="line">arr[j+gap] = arr[j]</span><br><span class="line">j -= gap</span><br><span class="line">}</span><br><span class="line">arr[j+gap] = temp</span><br><span class="line">}</span><br><span class="line">gap = gap / <span class="number">3</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> arr</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="5-Java-代码实现"><a href="#5-Java-代码实现" class="headerlink" title="5. Java 代码实现"></a>5. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ShellSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="comment">// 对 arr 进行拷贝,不改变参数内容</span></span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> gap = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span> (gap < arr.length) {</span><br><span class="line"> gap = gap * <span class="number">3</span> + <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (gap > <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = gap; i < arr.length; i++) {</span><br><span class="line"> <span class="keyword">int</span> tmp = arr[i];</span><br><span class="line"> <span class="keyword">int</span> j = i - gap;</span><br><span class="line"> <span class="keyword">while</span> (j >= <span class="number">0</span> && arr[j] > tmp) {</span><br><span class="line"> arr[j + gap] = arr[j];</span><br><span class="line"> j -= gap;</span><br><span class="line"> }</span><br><span class="line"> arr[j + gap] = tmp;</span><br><span class="line"> }</span><br><span class="line"> gap = (<span class="keyword">int</span>) Math.floor(gap / <span class="number">3</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="6-PHP-代码实现"><a href="#6-PHP-代码实现" class="headerlink" title="6. PHP 代码实现"></a>6. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">shellSort</span><span class="params">($arr)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> $len = count($arr);</span><br><span class="line"> $temp = <span class="number">0</span>;</span><br><span class="line"> $gap = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span>($gap < $len / <span class="number">3</span>) {</span><br><span class="line"> $gap = $gap * <span class="number">3</span> + <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span> ($gap; $gap > <span class="number">0</span>; $gap = floor($gap / <span class="number">3</span>)) {</span><br><span class="line"> <span class="keyword">for</span> ($i = $gap; $i < $len; $i++) {</span><br><span class="line"> $temp = $arr[$i];</span><br><span class="line"> <span class="keyword">for</span> ($j = $i - $gap; $j >= <span class="number">0</span> && $arr[$j] > $temp; $j -= $gap) {</span><br><span class="line"> $arr[$j+$gap] = $arr[$j];</span><br><span class="line"> }</span><br><span class="line"> $arr[$j+$gap] = $temp;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>希尔排序,也称递减增量排序算法,是插入排序的一种更高效的改进版本。但希尔排序是非稳定排序算法。</p>
<p>希尔排序是基于插入排序的以下两点性质而提出改进方法的:</p>
<ul>
<li>插入排序在对几乎已经排好序的数据操作时,效率高,即可以达到线性排序的效率;</li
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>桶排序</title>
<link href="http://junjun.vip/2019/07/05/9.bucketSort/"/>
<id>http://junjun.vip/2019/07/05/9.bucketSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:33:19.751Z</updated>
<content type="html"><![CDATA[<p>桶排序是计数排序的升级版。它利用了函数的映射关系,高效与否的关键就在于这个映射函数的确定。为了使桶排序更加高效,我们需要做到这两点:</p><ol><li>在额外空间充足的情况下,尽量增大桶的数量</li><li>使用的映射函数能够将输入的 N 个数据均匀的分配到 K 个桶中</li></ol><p>同时,对于桶中元素的排序,选择何种比较排序算法对于性能的影响至关重要。</p><h2 id="1-什么时候最快"><a href="#1-什么时候最快" class="headerlink" title="1. 什么时候最快"></a>1. 什么时候最快</h2><p>当输入的数据可以均匀的分配到每一个桶中。</p><h2 id="2-什么时候最慢"><a href="#2-什么时候最慢" class="headerlink" title="2. 什么时候最慢"></a>2. 什么时候最慢</h2><p>当输入的数据被分配到了同一个桶中。</p><h2 id="3-JavaScript-代码实现"><a href="#3-JavaScript-代码实现" class="headerlink" title="3. JavaScript 代码实现"></a>3. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">bucketSort</span>(<span class="params">arr, bucketSize</span>) </span>{</span><br><span class="line"> <span class="keyword">if</span> (arr.length === <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">var</span> i;</span><br><span class="line"> <span class="keyword">var</span> minValue = arr[<span class="number">0</span>];</span><br><span class="line"> <span class="keyword">var</span> maxValue = arr[<span class="number">0</span>];</span><br><span class="line"> <span class="keyword">for</span> (i = <span class="number">1</span>; i < arr.length; i++) {</span><br><span class="line"> <span class="keyword">if</span> (arr[i] < minValue) {</span><br><span class="line"> minValue = arr[i]; <span class="comment">// 输入数据的最小值</span></span><br><span class="line"> } <span class="keyword">else</span> <span class="keyword">if</span> (arr[i] > maxValue) {</span><br><span class="line"> maxValue = arr[i]; <span class="comment">// 输入数据的最大值</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">//桶的初始化</span></span><br><span class="line"> <span class="keyword">var</span> DEFAULT_BUCKET_SIZE = <span class="number">5</span>; <span class="comment">// 设置桶的默认数量为5</span></span><br><span class="line"> bucketSize = bucketSize || DEFAULT_BUCKET_SIZE;</span><br><span class="line"> <span class="keyword">var</span> bucketCount = <span class="built_in">Math</span>.floor((maxValue - minValue) / bucketSize) + <span class="number">1</span>; </span><br><span class="line"> <span class="keyword">var</span> buckets = <span class="keyword">new</span> <span class="built_in">Array</span>(bucketCount);</span><br><span class="line"> <span class="keyword">for</span> (i = <span class="number">0</span>; i < buckets.length; i++) {</span><br><span class="line"> buckets[i] = [];</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">//利用映射函数将数据分配到各个桶中</span></span><br><span class="line"> <span class="keyword">for</span> (i = <span class="number">0</span>; i < arr.length; i++) {</span><br><span class="line"> buckets[<span class="built_in">Math</span>.floor((arr[i] - minValue) / bucketSize)].push(arr[i]);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> arr.length = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> (i = <span class="number">0</span>; i < buckets.length; i++) {</span><br><span class="line"> insertionSort(buckets[i]); <span class="comment">// 对每个桶进行排序,这里使用了插入排序</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> j = <span class="number">0</span>; j < buckets[i].length; j++) {</span><br><span class="line"> arr.push(buckets[i][j]); </span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="4-Java-代码实现"><a href="#4-Java-代码实现" class="headerlink" title="4. Java 代码实现"></a>4. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BucketSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> InsertSort insertSort = <span class="keyword">new</span> InsertSort();</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="comment">// 对 arr 进行拷贝,不改变参数内容</span></span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> bucketSort(arr, <span class="number">5</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">int</span>[] bucketSort(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> bucketSize) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="keyword">if</span> (arr.length == <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> minValue = arr[<span class="number">0</span>];</span><br><span class="line"> <span class="keyword">int</span> maxValue = arr[<span class="number">0</span>];</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> value : arr) {</span><br><span class="line"> <span class="keyword">if</span> (value < minValue) {</span><br><span class="line"> minValue = value;</span><br><span class="line"> } <span class="keyword">else</span> <span class="keyword">if</span> (value > maxValue) {</span><br><span class="line"> maxValue = value;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> bucketCount = (<span class="keyword">int</span>) Math.floor((maxValue - minValue) / bucketSize) + <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">int</span>[][] buckets = <span class="keyword">new</span> <span class="keyword">int</span>[bucketCount][<span class="number">0</span>];</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 利用映射函数将数据分配到各个桶中</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i < arr.length; i++) {</span><br><span class="line"> <span class="keyword">int</span> index = (<span class="keyword">int</span>) Math.floor((arr[i] - minValue) / bucketSize);</span><br><span class="line"> buckets[index] = arrAppend(buckets[index], arr[i]);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> arrIndex = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span>[] bucket : buckets) {</span><br><span class="line"> <span class="keyword">if</span> (bucket.length <= <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">continue</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// 对每个桶进行排序,这里使用了插入排序</span></span><br><span class="line"> bucket = insertSort.sort(bucket);</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> value : bucket) {</span><br><span class="line"> arr[arrIndex++] = value;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 自动扩容,并保存数据</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> arr</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> value</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">int</span>[] arrAppend(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> value) {</span><br><span class="line"> arr = Arrays.copyOf(arr, arr.length + <span class="number">1</span>);</span><br><span class="line"> arr[arr.length - <span class="number">1</span>] = value;</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="5-PHP-代码实现"><a href="#5-PHP-代码实现" class="headerlink" title="5. PHP 代码实现"></a>5. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">bucketSort</span><span class="params">($arr, $bucketSize = <span class="number">5</span>)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span> (count($arr) === <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> $minValue = $arr[<span class="number">0</span>];</span><br><span class="line"> $maxValue = $arr[<span class="number">0</span>];</span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">1</span>; $i < count($arr); $i++) {</span><br><span class="line"> <span class="keyword">if</span> ($arr[$i] < $minValue) {</span><br><span class="line"> $minValue = $arr[$i];</span><br><span class="line"> } <span class="keyword">else</span> <span class="keyword">if</span> ($arr[$i] > $maxValue) {</span><br><span class="line"> $maxValue = $arr[$i];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> $bucketCount = floor(($maxValue - $minValue) / $bucketSize) + <span class="number">1</span>;</span><br><span class="line"> $buckets = <span class="keyword">array</span>();</span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">0</span>; $i < count($buckets); $i++) {</span><br><span class="line"> $buckets[$i] = [];</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">0</span>; $i < count($arr); $i++) {</span><br><span class="line"> $buckets[floor(($arr[$i] - $minValue) / $bucketSize)][] = $arr[$i];</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> $arr = <span class="keyword">array</span>();</span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">0</span>; $i < count($buckets); $i++) {</span><br><span class="line"> $bucketTmp = $buckets[$i];</span><br><span class="line"> sort($bucketTmp);</span><br><span class="line"> <span class="keyword">for</span> ($j = <span class="number">0</span>; $j < count($bucketTmp); $j++) {</span><br><span class="line"> $arr[] = $bucketTmp[$j];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>桶排序是计数排序的升级版。它利用了函数的映射关系,高效与否的关键就在于这个映射函数的确定。为了使桶排序更加高效,我们需要做到这两点:</p>
<ol>
<li>在额外空间充足的情况下,尽量增大桶的数量</li>
<li>使用的映射函数能够将输入的 N 个数据均匀的分配到 K
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>归并排序</title>
<link href="http://junjun.vip/2019/07/05/5.mergeSort/"/>
<id>http://junjun.vip/2019/07/05/5.mergeSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:33:03.088Z</updated>
<content type="html"><![CDATA[<p>归并排序(Merge sort)是建立在归并操作上的一种有效的排序算法。该算法是采用分治法(Divide and Conquer)的一个非常典型的应用。</p><p>作为一种典型的分而治之思想的算法应用,归并排序的实现由两种方法:</p><ul><li>自上而下的递归(所有递归的方法都可以用迭代重写,所以就有了第 2 种方法);</li><li>自下而上的迭代;</li></ul><p>在《数据结构与算法 JavaScript 描述》中,作者给出了自下而上的迭代方法。但是对于递归法,作者却认为:</p><blockquote><p>However, it is not possible to do so in JavaScript, as the recursion goes too deep for the language to handle.</p><p>然而,在 JavaScript 中这种方式不太可行,因为这个算法的递归深度对它来讲太深了。</p></blockquote><p>说实话,我不太理解这句话。意思是 JavaScript 编译器内存太小,递归太深容易造成内存溢出吗?还望有大神能够指教。</p><p>和选择排序一样,归并排序的性能不受输入数据的影响,但表现比选择排序好的多,因为始终都是 O(nlogn) 的时间复杂度。代价是需要额外的内存空间。</p><h2 id="2-算法步骤"><a href="#2-算法步骤" class="headerlink" title="2. 算法步骤"></a>2. 算法步骤</h2><ol><li><p>申请空间,使其大小为两个已经排序序列之和,该空间用来存放合并后的序列;</p></li><li><p>设定两个指针,最初位置分别为两个已经排序序列的起始位置;</p></li><li><p>比较两个指针所指向的元素,选择相对小的元素放入到合并空间,并移动指针到下一位置;</p></li><li><p>重复步骤 3 直到某一指针达到序列尾;</p></li><li><p>将另一序列剩下的所有元素直接复制到合并序列尾。</p></li></ol><h2 id="3-动图演示"><a href="#3-动图演示" class="headerlink" title="3. 动图演示"></a>3. 动图演示</h2><p><img src="/images/sort/mergeSort.gif" alt="动图演示"></p><h2 id="4-JavaScript-代码实现"><a href="#4-JavaScript-代码实现" class="headerlink" title="4. JavaScript 代码实现"></a>4. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">mergeSort</span>(<span class="params">arr</span>) </span>{ <span class="comment">// 采用自上而下的递归方法</span></span><br><span class="line"> <span class="keyword">var</span> len = arr.length;</span><br><span class="line"> <span class="keyword">if</span>(len < <span class="number">2</span>) {</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">var</span> middle = <span class="built_in">Math</span>.floor(len / <span class="number">2</span>),</span><br><span class="line"> left = arr.slice(<span class="number">0</span>, middle),</span><br><span class="line"> right = arr.slice(middle);</span><br><span class="line"> <span class="keyword">return</span> merge(mergeSort(left), mergeSort(right));</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">merge</span>(<span class="params">left, right</span>)</span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">var</span> result = [];</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (left.length && right.length) {</span><br><span class="line"> <span class="keyword">if</span> (left[<span class="number">0</span>] <= right[<span class="number">0</span>]) {</span><br><span class="line"> result.push(left.shift());</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> result.push(right.shift());</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (left.length)</span><br><span class="line"> result.push(left.shift());</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (right.length)</span><br><span class="line"> result.push(right.shift());</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> result;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="5-Python-代码实现"><a href="#5-Python-代码实现" class="headerlink" title="5. Python 代码实现"></a>5. Python 代码实现</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">mergeSort</span><span class="params">(arr)</span>:</span></span><br><span class="line"> <span class="keyword">import</span> math</span><br><span class="line"> <span class="keyword">if</span>(len(arr)<<span class="number">2</span>):</span><br><span class="line"> <span class="keyword">return</span> arr</span><br><span class="line"> middle = math.floor(len(arr)/<span class="number">2</span>)</span><br><span class="line"> left, right = arr[<span class="number">0</span>:middle], arr[middle:]</span><br><span class="line"> <span class="keyword">return</span> merge(mergeSort(left), mergeSort(right))</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">merge</span><span class="params">(left,right)</span>:</span></span><br><span class="line"> result = []</span><br><span class="line"> <span class="keyword">while</span> left <span class="keyword">and</span> right:</span><br><span class="line"> <span class="keyword">if</span> left[<span class="number">0</span>] <= right[<span class="number">0</span>]:</span><br><span class="line"> result.append(left.pop(<span class="number">0</span>));</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> result.append(right.pop(<span class="number">0</span>));</span><br><span class="line"> <span class="keyword">while</span> left:</span><br><span class="line"> result.append(left.pop(<span class="number">0</span>));</span><br><span class="line"> <span class="keyword">while</span> right:</span><br><span class="line"> result.append(right.pop(<span class="number">0</span>));</span><br><span class="line"> <span class="keyword">return</span> result</span><br></pre></td></tr></table></figure><h2 id="6-Go-代码实现"><a href="#6-Go-代码实现" class="headerlink" title="6. Go 代码实现"></a>6. Go 代码实现</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">mergeSort</span><span class="params">(arr []<span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line">length := <span class="built_in">len</span>(arr)</span><br><span class="line"><span class="keyword">if</span> length < <span class="number">2</span> {</span><br><span class="line"><span class="keyword">return</span> arr</span><br><span class="line">}</span><br><span class="line">middle := length / <span class="number">2</span></span><br><span class="line">left := arr[<span class="number">0</span>:middle]</span><br><span class="line">right := arr[middle:]</span><br><span class="line"><span class="keyword">return</span> merge(mergeSort(left), mergeSort(right))</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">merge</span><span class="params">(left []<span class="keyword">int</span>, right []<span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line"><span class="keyword">var</span> result []<span class="keyword">int</span></span><br><span class="line"><span class="keyword">for</span> <span class="built_in">len</span>(left) != <span class="number">0</span> && <span class="built_in">len</span>(right) != <span class="number">0</span> {</span><br><span class="line"><span class="keyword">if</span> left[<span class="number">0</span>] <= right[<span class="number">0</span>] {</span><br><span class="line">result = <span class="built_in">append</span>(result, left[<span class="number">0</span>])</span><br><span class="line">left = left[<span class="number">1</span>:]</span><br><span class="line">} <span class="keyword">else</span> {</span><br><span class="line">result = <span class="built_in">append</span>(result, right[<span class="number">0</span>])</span><br><span class="line">right = right[<span class="number">1</span>:]</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> <span class="built_in">len</span>(left) != <span class="number">0</span> {</span><br><span class="line">result = <span class="built_in">append</span>(result, left[<span class="number">0</span>])</span><br><span class="line">left = left[<span class="number">1</span>:]</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> <span class="built_in">len</span>(right) != <span class="number">0</span> {</span><br><span class="line">result = <span class="built_in">append</span>(result, right[<span class="number">0</span>])</span><br><span class="line">right = right[<span class="number">1</span>:]</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">return</span> result</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="7-Java-代码实现"><a href="#7-Java-代码实现" class="headerlink" title="7. Java 代码实现"></a>7. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MergeSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="comment">// 对 arr 进行拷贝,不改变参数内容</span></span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (arr.length < <span class="number">2</span>) {</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> middle = (<span class="keyword">int</span>) Math.floor(arr.length / <span class="number">2</span>);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span>[] left = Arrays.copyOfRange(arr, <span class="number">0</span>, middle);</span><br><span class="line"> <span class="keyword">int</span>[] right = Arrays.copyOfRange(arr, middle, arr.length);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> merge(sort(left), sort(right));</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">protected</span> <span class="keyword">int</span>[] merge(<span class="keyword">int</span>[] left, <span class="keyword">int</span>[] right) {</span><br><span class="line"> <span class="keyword">int</span>[] result = <span class="keyword">new</span> <span class="keyword">int</span>[left.length + right.length];</span><br><span class="line"> <span class="keyword">int</span> i = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span> (left.length > <span class="number">0</span> && right.length > <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">if</span> (left[<span class="number">0</span>] <= right[<span class="number">0</span>]) {</span><br><span class="line"> result[i++] = left[<span class="number">0</span>];</span><br><span class="line"> left = Arrays.copyOfRange(left, <span class="number">1</span>, left.length);</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> result[i++] = right[<span class="number">0</span>];</span><br><span class="line"> right = Arrays.copyOfRange(right, <span class="number">1</span>, right.length);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (left.length > <span class="number">0</span>) {</span><br><span class="line"> result[i++] = left[<span class="number">0</span>];</span><br><span class="line"> left = Arrays.copyOfRange(left, <span class="number">1</span>, left.length);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (right.length > <span class="number">0</span>) {</span><br><span class="line"> result[i++] = right[<span class="number">0</span>];</span><br><span class="line"> right = Arrays.copyOfRange(right, <span class="number">1</span>, right.length);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> result;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="8-PHP-代码实现"><a href="#8-PHP-代码实现" class="headerlink" title="8. PHP 代码实现"></a>8. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">mergeSort</span><span class="params">($arr)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> $len = count($arr);</span><br><span class="line"> <span class="keyword">if</span> ($len < <span class="number">2</span>) {</span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line"> }</span><br><span class="line"> $middle = floor($len / <span class="number">2</span>);</span><br><span class="line"> $left = array_slice($arr, <span class="number">0</span>, $middle);</span><br><span class="line"> $right = array_slice($arr, $middle);</span><br><span class="line"> <span class="keyword">return</span> merge(mergeSort($left), mergeSort($right));</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">merge</span><span class="params">($left, $right)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> $result = [];</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (count($left) > <span class="number">0</span> && count($right) > <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">if</span> ($left[<span class="number">0</span>] <= $right[<span class="number">0</span>]) {</span><br><span class="line"> $result[] = array_shift($left);</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> $result[] = array_shift($right);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (count($left))</span><br><span class="line"> $result[] = array_shift($left);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span> (count($right))</span><br><span class="line"> $result[] = array_shift($right);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> $result;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>归并排序(Merge sort)是建立在归并操作上的一种有效的排序算法。该算法是采用分治法(Divide and Conquer)的一个非常典型的应用。</p>
<p>作为一种典型的分而治之思想的算法应用,归并排序的实现由两种方法:</p>
<ul>
<li>自上而下的递归
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>快速排序</title>
<link href="http://junjun.vip/2019/07/05/6.quickSort/"/>
<id>http://junjun.vip/2019/07/05/6.quickSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:33:06.652Z</updated>
<content type="html"><![CDATA[<p>快速排序是由东尼·霍尔所发展的一种排序算法。在平均状况下,排序 n 个项目要 Ο(nlogn) 次比较。在最坏状况下则需要 Ο(n2) 次比较,但这种状况并不常见。事实上,快速排序通常明显比其他 Ο(nlogn) 算法更快,因为它的内部循环(inner loop)可以在大部分的架构上很有效率地被实现出来。</p><p>快速排序使用分治法(Divide and conquer)策略来把一个串行(list)分为两个子串行(sub-lists)。</p><p>快速排序又是一种分而治之思想在排序算法上的典型应用。本质上来看,快速排序应该算是在冒泡排序基础上的递归分治法。</p><p>快速排序的名字起的是简单粗暴,因为一听到这个名字你就知道它存在的意义,就是快,而且效率高!它是处理大数据最快的排序算法之一了。虽然 Worst Case 的时间复杂度达到了 O(n²),但是人家就是优秀,在大多数情况下都比平均时间复杂度为 O(n logn) 的排序算法表现要更好,可是这是为什么呢,我也不知道。好在我的强迫症又犯了,查了 N 多资料终于在《算法艺术与信息学竞赛》上找到了满意的答案:</p><blockquote><p>快速排序的最坏运行情况是 O(n²),比如说顺序数列的快排。但它的平摊期望时间是 O(nlogn),且 O(nlogn) 记号中隐含的常数因子很小,比复杂度稳定等于 O(nlogn) 的归并排序要小很多。所以,对绝大多数顺序性较弱的随机数列而言,快速排序总是优于归并排序。</p></blockquote><h2 id="1-算法步骤"><a href="#1-算法步骤" class="headerlink" title="1. 算法步骤"></a>1. 算法步骤</h2><ol><li><p>从数列中挑出一个元素,称为 “基准”(pivot);</p></li><li><p>重新排序数列,所有元素比基准值小的摆放在基准前面,所有元素比基准值大的摆在基准的后面(相同的数可以到任一边)。在这个分区退出之后,该基准就处于数列的中间位置。这个称为分区(partition)操作;</p></li><li><p>递归地(recursive)把小于基准值元素的子数列和大于基准值元素的子数列排序;</p></li></ol><p>递归的最底部情形,是数列的大小是零或一,也就是永远都已经被排序好了。虽然一直递归下去,但是这个算法总会退出,因为在每次的迭代(iteration)中,它至少会把一个元素摆到它最后的位置去。</p><h2 id="2-动图演示"><a href="#2-动图演示" class="headerlink" title="2. 动图演示"></a>2. 动图演示</h2><p><img src="/images/sort/quickSort.gif" alt="动图演示"></p><h2 id="3-JavaScript-代码实现"><a href="#3-JavaScript-代码实现" class="headerlink" title="3. JavaScript 代码实现"></a>3. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">quickSort</span>(<span class="params">arr, left, right</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> len = arr.length,</span><br><span class="line"> partitionIndex,</span><br><span class="line"> left = <span class="keyword">typeof</span> left != <span class="string">'number'</span> ? <span class="number">0</span> : left,</span><br><span class="line"> right = <span class="keyword">typeof</span> right != <span class="string">'number'</span> ? len - <span class="number">1</span> : right;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (left < right) {</span><br><span class="line"> partitionIndex = partition(arr, left, right);</span><br><span class="line"> quickSort(arr, left, partitionIndex<span class="number">-1</span>);</span><br><span class="line"> quickSort(arr, partitionIndex+<span class="number">1</span>, right);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">partition</span>(<span class="params">arr, left ,right</span>) </span>{ <span class="comment">// 分区操作</span></span><br><span class="line"> <span class="keyword">var</span> pivot = left, <span class="comment">// 设定基准值(pivot)</span></span><br><span class="line"> index = pivot + <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = index; i <= right; i++) {</span><br><span class="line"> <span class="keyword">if</span> (arr[i] < arr[pivot]) {</span><br><span class="line"> swap(arr, i, index);</span><br><span class="line"> index++;</span><br><span class="line"> } </span><br><span class="line"> }</span><br><span class="line"> swap(arr, pivot, index - <span class="number">1</span>);</span><br><span class="line"> <span class="keyword">return</span> index<span class="number">-1</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">swap</span>(<span class="params">arr, i, j</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> temp = arr[i];</span><br><span class="line"> arr[i] = arr[j];</span><br><span class="line"> arr[j] = temp;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">partition2</span>(<span class="params">arr, low, high</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> pivot = arr[low];</span><br><span class="line"> <span class="keyword">while</span> (low < high) {</span><br><span class="line"> <span class="keyword">while</span> (low < high && arr[high] > pivot) {</span><br><span class="line"> --high;</span><br><span class="line"> }</span><br><span class="line"> arr[low] = arr[high];</span><br><span class="line"> <span class="keyword">while</span> (low < high && arr[low] <= pivot) {</span><br><span class="line"> ++low;</span><br><span class="line"> }</span><br><span class="line"> arr[high] = arr[low];</span><br><span class="line"> }</span><br><span class="line"> arr[low] = pivot;</span><br><span class="line"> <span class="keyword">return</span> low;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">quickSort2</span>(<span class="params">arr, low, high</span>) </span>{</span><br><span class="line"> <span class="keyword">if</span> (low < high) {</span><br><span class="line"> <span class="keyword">let</span> pivot = partition2(arr, low, high);</span><br><span class="line"> quickSort2(arr, low, pivot - <span class="number">1</span>);</span><br><span class="line"> quickSort2(arr, pivot + <span class="number">1</span>, high);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="4-Python-代码实现"><a href="#4-Python-代码实现" class="headerlink" title="4. Python 代码实现"></a>4. Python 代码实现</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">quickSort</span><span class="params">(arr, left=None, right=None)</span>:</span></span><br><span class="line"> left = <span class="number">0</span> <span class="keyword">if</span> <span class="keyword">not</span> isinstance(left,(int, float)) <span class="keyword">else</span> left</span><br><span class="line"> right = len(arr)<span class="number">-1</span> <span class="keyword">if</span> <span class="keyword">not</span> isinstance(right,(int, float)) <span class="keyword">else</span> right</span><br><span class="line"> <span class="keyword">if</span> left < right:</span><br><span class="line"> partitionIndex = partition(arr, left, right)</span><br><span class="line"> quickSort(arr, left, partitionIndex<span class="number">-1</span>)</span><br><span class="line"> quickSort(arr, partitionIndex+<span class="number">1</span>, right)</span><br><span class="line"> <span class="keyword">return</span> arr</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">partition</span><span class="params">(arr, left, right)</span>:</span></span><br><span class="line"> pivot = left</span><br><span class="line"> index = pivot+<span class="number">1</span></span><br><span class="line"> i = index</span><br><span class="line"> <span class="keyword">while</span> i <= right:</span><br><span class="line"> <span class="keyword">if</span> arr[i] < arr[pivot]:</span><br><span class="line"> swap(arr, i, index)</span><br><span class="line"> index+=<span class="number">1</span></span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"> swap(arr,pivot,index<span class="number">-1</span>)</span><br><span class="line"> <span class="keyword">return</span> index<span class="number">-1</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">swap</span><span class="params">(arr, i, j)</span>:</span></span><br><span class="line"> arr[i], arr[j] = arr[j], arr[i]</span><br></pre></td></tr></table></figure><h2 id="5-Go-代码实现"><a href="#5-Go-代码实现" class="headerlink" title="5. Go 代码实现"></a>5. Go 代码实现</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">quickSort</span><span class="params">(arr []<span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line"><span class="keyword">return</span> _quickSort(arr, <span class="number">0</span>, <span class="built_in">len</span>(arr)<span class="number">-1</span>)</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> _<span class="title">quickSort</span><span class="params">(arr []<span class="keyword">int</span>, left, right <span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line"><span class="keyword">if</span> left < right {</span><br><span class="line">partitionIndex := partition(arr, left, right)</span><br><span class="line">_quickSort(arr, left, partitionIndex<span class="number">-1</span>)</span><br><span class="line">_quickSort(arr, partitionIndex+<span class="number">1</span>, right)</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> arr</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">partition</span><span class="params">(arr []<span class="keyword">int</span>, left, right <span class="keyword">int</span>)</span> <span class="title">int</span></span> {</span><br><span class="line">pivot := left</span><br><span class="line">index := pivot + <span class="number">1</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> i := index; i <= right; i++ {</span><br><span class="line"><span class="keyword">if</span> arr[i] < arr[pivot] {</span><br><span class="line">swap(arr, i, index)</span><br><span class="line">index += <span class="number">1</span></span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">swap(arr, pivot, index<span class="number">-1</span>)</span><br><span class="line"><span class="keyword">return</span> index - <span class="number">1</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">swap</span><span class="params">(arr []<span class="keyword">int</span>, i, j <span class="keyword">int</span>)</span></span> {</span><br><span class="line">arr[i], arr[j] = arr[j], arr[i]</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="6-C-版"><a href="#6-C-版" class="headerlink" title="6. C++版"></a>6. C++版</h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//严蔚敏《数据结构》标准分割函数</span></span><br><span class="line">Paritition1(<span class="keyword">int</span> A[], <span class="keyword">int</span> low, <span class="keyword">int</span> high) {</span><br><span class="line"> <span class="keyword">int</span> pivot = A[low];</span><br><span class="line"> <span class="keyword">while</span> (low < high) {</span><br><span class="line"> <span class="keyword">while</span> (low < high && A[high] >= pivot) {</span><br><span class="line"> --high;</span><br><span class="line"> }</span><br><span class="line"> A[low] = A[high];</span><br><span class="line"> <span class="keyword">while</span> (low < high && A[low] <= pivot) {</span><br><span class="line"> ++low;</span><br><span class="line"> }</span><br><span class="line"> A[high] = A[low];</span><br><span class="line"> }</span><br><span class="line"> A[low] = pivot;</span><br><span class="line"> <span class="keyword">return</span> low;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">QuickSort</span><span class="params">(<span class="keyword">int</span> A[], <span class="keyword">int</span> low, <span class="keyword">int</span> high)</span> <span class="comment">//快排母函数</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span> (low < high) {</span><br><span class="line"> <span class="keyword">int</span> pivot = Paritition1(A, low, high);</span><br><span class="line"> QuickSort(A, low, pivot - <span class="number">1</span>);</span><br><span class="line"> QuickSort(A, pivot + <span class="number">1</span>, high);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="7-Java-代码实现"><a href="#7-Java-代码实现" class="headerlink" title="7. Java 代码实现"></a>7. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">QuickSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="comment">// 对 arr 进行拷贝,不改变参数内容</span></span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> quickSort(arr, <span class="number">0</span>, arr.length - <span class="number">1</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">int</span>[] quickSort(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> left, <span class="keyword">int</span> right) {</span><br><span class="line"> <span class="keyword">if</span> (left < right) {</span><br><span class="line"> <span class="keyword">int</span> partitionIndex = partition(arr, left, right);</span><br><span class="line"> quickSort(arr, left, partitionIndex - <span class="number">1</span>);</span><br><span class="line"> quickSort(arr, partitionIndex + <span class="number">1</span>, right);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">partition</span><span class="params">(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> left, <span class="keyword">int</span> right)</span> </span>{</span><br><span class="line"> <span class="comment">// 设定基准值(pivot)</span></span><br><span class="line"> <span class="keyword">int</span> pivot = left;</span><br><span class="line"> <span class="keyword">int</span> index = pivot + <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = index; i <= right; i++) {</span><br><span class="line"> <span class="keyword">if</span> (arr[i] < arr[pivot]) {</span><br><span class="line"> swap(arr, i, index);</span><br><span class="line"> index++;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> swap(arr, pivot, index - <span class="number">1</span>);</span><br><span class="line"> <span class="keyword">return</span> index - <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">swap</span><span class="params">(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> i, <span class="keyword">int</span> j)</span> </span>{</span><br><span class="line"> <span class="keyword">int</span> temp = arr[i];</span><br><span class="line"> arr[i] = arr[j];</span><br><span class="line"> arr[j] = temp;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="8-PHP-代码实现"><a href="#8-PHP-代码实现" class="headerlink" title="8. PHP 代码实现"></a>8. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">quickSort</span><span class="params">($arr)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span> (count($arr) <= <span class="number">1</span>)</span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line"> $middle = $arr[<span class="number">0</span>];</span><br><span class="line"> $leftArray = <span class="keyword">array</span>();</span><br><span class="line"> $rightArray = <span class="keyword">array</span>();</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">1</span>; $i < count($arr); $i++) {</span><br><span class="line"> <span class="keyword">if</span> ($arr[$i] > $middle)</span><br><span class="line"> $rightArray[] = $arr[$i];</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> $leftArray[] = $arr[$i];</span><br><span class="line"> }</span><br><span class="line"> $leftArray = quickSort($leftArray);</span><br><span class="line"> $leftArray[] = $middle;</span><br><span class="line"></span><br><span class="line"> $rightArray = quickSort($rightArray);</span><br><span class="line"> <span class="keyword">return</span> array_merge($leftArray, $rightArray);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>快速排序是由东尼·霍尔所发展的一种排序算法。在平均状况下,排序 n 个项目要 Ο(nlogn) 次比较。在最坏状况下则需要 Ο(n2) 次比较,但这种状况并不常见。事实上,快速排序通常明显比其他 Ο(nlogn) 算法更快,因为它的内部循环(inner loop)可以在大部
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>堆排序</title>
<link href="http://junjun.vip/2019/07/05/7.heapSort/"/>
<id>http://junjun.vip/2019/07/05/7.heapSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:33:11.862Z</updated>
<content type="html"><![CDATA[<p>堆排序(Heapsort)是指利用堆这种数据结构所设计的一种排序算法。堆积是一个近似完全二叉树的结构,并同时满足堆积的性质:即子结点的键值或索引总是小于(或者大于)它的父节点。堆排序可以说是一种利用堆的概念来排序的选择排序。分为两种方法:</p><ol><li>大顶堆:每个节点的值都大于或等于其子节点的值,在堆排序算法中用于升序排列;</li><li>小顶堆:每个节点的值都小于或等于其子节点的值,在堆排序算法中用于降序排列;</li></ol><p>堆排序的平均时间复杂度为 Ο(nlogn)。</p><h2 id="1-算法步骤"><a href="#1-算法步骤" class="headerlink" title="1. 算法步骤"></a>1. 算法步骤</h2><ol><li><p>创建一个堆 H[0……n-1];</p></li><li><p>把堆首(最大值)和堆尾互换;</p></li><li><p>把堆的尺寸缩小 1,并调用 shift_down(0),目的是把新的数组顶端数据调整到相应位置;</p></li><li><p>重复步骤 2,直到堆的尺寸为 1。</p></li></ol><h2 id="2-动图演示"><a href="#2-动图演示" class="headerlink" title="2. 动图演示"></a>2. 动图演示</h2><p><img src="/images/sort/heapSort.gif" alt="动图演示"></p><h2 id="3-JavaScript-代码实现"><a href="#3-JavaScript-代码实现" class="headerlink" title="3. JavaScript 代码实现"></a>3. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> len; <span class="comment">// 因为声明的多个函数都需要数据长度,所以把len设置成为全局变量</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">buildMaxHeap</span>(<span class="params">arr</span>) </span>{ <span class="comment">// 建立大顶堆</span></span><br><span class="line"> len = arr.length;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="built_in">Math</span>.floor(len/<span class="number">2</span>); i >= <span class="number">0</span>; i--) {</span><br><span class="line"> heapify(arr, i);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">heapify</span>(<span class="params">arr, i</span>) </span>{ <span class="comment">// 堆调整</span></span><br><span class="line"> <span class="keyword">var</span> left = <span class="number">2</span> * i + <span class="number">1</span>,</span><br><span class="line"> right = <span class="number">2</span> * i + <span class="number">2</span>,</span><br><span class="line"> largest = i;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (left < len && arr[left] > arr[largest]) {</span><br><span class="line"> largest = left;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (right < len && arr[right] > arr[largest]) {</span><br><span class="line"> largest = right;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (largest != i) {</span><br><span class="line"> swap(arr, i, largest);</span><br><span class="line"> heapify(arr, largest);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">swap</span>(<span class="params">arr, i, j</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> temp = arr[i];</span><br><span class="line"> arr[i] = arr[j];</span><br><span class="line"> arr[j] = temp;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">heapSort</span>(<span class="params">arr</span>) </span>{</span><br><span class="line"> buildMaxHeap(arr);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = arr.length<span class="number">-1</span>; i > <span class="number">0</span>; i--) {</span><br><span class="line"> swap(arr, <span class="number">0</span>, i);</span><br><span class="line"> len--;</span><br><span class="line"> heapify(arr, <span class="number">0</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="4-Python-代码实现"><a href="#4-Python-代码实现" class="headerlink" title="4. Python 代码实现"></a>4. Python 代码实现</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">buildMaxHeap</span><span class="params">(arr)</span>:</span></span><br><span class="line"> <span class="keyword">import</span> math</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(math.floor(len(arr)/<span class="number">2</span>),<span class="number">-1</span>,<span class="number">-1</span>):</span><br><span class="line"> heapify(arr,i)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">heapify</span><span class="params">(arr, i)</span>:</span></span><br><span class="line"> left = <span class="number">2</span>*i+<span class="number">1</span></span><br><span class="line"> right = <span class="number">2</span>*i+<span class="number">2</span></span><br><span class="line"> largest = i</span><br><span class="line"> <span class="keyword">if</span> left < arrLen <span class="keyword">and</span> arr[left] > arr[largest]:</span><br><span class="line"> largest = left</span><br><span class="line"> <span class="keyword">if</span> right < arrLen <span class="keyword">and</span> arr[right] > arr[largest]:</span><br><span class="line"> largest = right</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> largest != i:</span><br><span class="line"> swap(arr, i, largest)</span><br><span class="line"> heapify(arr, largest)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">swap</span><span class="params">(arr, i, j)</span>:</span></span><br><span class="line"> arr[i], arr[j] = arr[j], arr[i]</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">heapSort</span><span class="params">(arr)</span>:</span></span><br><span class="line"> <span class="keyword">global</span> arrLen</span><br><span class="line"> arrLen = len(arr)</span><br><span class="line"> buildMaxHeap(arr)</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(len(arr)<span class="number">-1</span>,<span class="number">0</span>,<span class="number">-1</span>):</span><br><span class="line"> swap(arr,<span class="number">0</span>,i)</span><br><span class="line"> arrLen -=<span class="number">1</span></span><br><span class="line"> heapify(arr, <span class="number">0</span>)</span><br><span class="line"> <span class="keyword">return</span> arr</span><br></pre></td></tr></table></figure><h2 id="5-Go-代码实现"><a href="#5-Go-代码实现" class="headerlink" title="5. Go 代码实现"></a>5. Go 代码实现</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">heapSort</span><span class="params">(arr []<span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line">arrLen := <span class="built_in">len</span>(arr)</span><br><span class="line">buildMaxHeap(arr, arrLen)</span><br><span class="line"><span class="keyword">for</span> i := arrLen - <span class="number">1</span>; i >= <span class="number">0</span>; i-- {</span><br><span class="line">swap(arr, <span class="number">0</span>, i)</span><br><span class="line">arrLen -= <span class="number">1</span></span><br><span class="line">heapify(arr, <span class="number">0</span>, arrLen)</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> arr</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">buildMaxHeap</span><span class="params">(arr []<span class="keyword">int</span>, arrLen <span class="keyword">int</span>)</span></span> {</span><br><span class="line"><span class="keyword">for</span> i := arrLen / <span class="number">2</span>; i >= <span class="number">0</span>; i-- {</span><br><span class="line">heapify(arr, i, arrLen)</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">heapify</span><span class="params">(arr []<span class="keyword">int</span>, i, arrLen <span class="keyword">int</span>)</span></span> {</span><br><span class="line">left := <span class="number">2</span>*i + <span class="number">1</span></span><br><span class="line">right := <span class="number">2</span>*i + <span class="number">2</span></span><br><span class="line">largest := i</span><br><span class="line"><span class="keyword">if</span> left < arrLen && arr[left] > arr[largest] {</span><br><span class="line">largest = left</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span> right < arrLen && arr[right] > arr[largest] {</span><br><span class="line">largest = right</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span> largest != i {</span><br><span class="line">swap(arr, i, largest)</span><br><span class="line">heapify(arr, largest, arrLen)</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">swap</span><span class="params">(arr []<span class="keyword">int</span>, i, j <span class="keyword">int</span>)</span></span> {</span><br><span class="line">arr[i], arr[j] = arr[j], arr[i]</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="6-Java-代码实现"><a href="#6-Java-代码实现" class="headerlink" title="6. Java 代码实现"></a>6. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HeapSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="comment">// 对 arr 进行拷贝,不改变参数内容</span></span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> len = arr.length;</span><br><span class="line"></span><br><span class="line"> buildMaxHeap(arr, len);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = len - <span class="number">1</span>; i > <span class="number">0</span>; i--) {</span><br><span class="line"> swap(arr, <span class="number">0</span>, i);</span><br><span class="line"> len--;</span><br><span class="line"> heapify(arr, <span class="number">0</span>, len);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">buildMaxHeap</span><span class="params">(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> len)</span> </span>{</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = (<span class="keyword">int</span>) Math.floor(len / <span class="number">2</span>); i >= <span class="number">0</span>; i--) {</span><br><span class="line"> heapify(arr, i, len);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">heapify</span><span class="params">(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> i, <span class="keyword">int</span> len)</span> </span>{</span><br><span class="line"> <span class="keyword">int</span> left = <span class="number">2</span> * i + <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">int</span> right = <span class="number">2</span> * i + <span class="number">2</span>;</span><br><span class="line"> <span class="keyword">int</span> largest = i;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (left < len && arr[left] > arr[largest]) {</span><br><span class="line"> largest = left;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (right < len && arr[right] > arr[largest]) {</span><br><span class="line"> largest = right;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (largest != i) {</span><br><span class="line"> swap(arr, i, largest);</span><br><span class="line"> heapify(arr, largest, len);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">swap</span><span class="params">(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> i, <span class="keyword">int</span> j)</span> </span>{</span><br><span class="line"> <span class="keyword">int</span> temp = arr[i];</span><br><span class="line"> arr[i] = arr[j];</span><br><span class="line"> arr[j] = temp;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="7-PHP-代码实现"><a href="#7-PHP-代码实现" class="headerlink" title="7. PHP 代码实现"></a>7. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">buildMaxHeap</span><span class="params">(&$arr)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">global</span> $len;</span><br><span class="line"> <span class="keyword">for</span> ($i = floor($len/<span class="number">2</span>); $i >= <span class="number">0</span>; $i--) {</span><br><span class="line"> heapify($arr, $i);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">heapify</span><span class="params">(&$arr, $i)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">global</span> $len;</span><br><span class="line"> $left = <span class="number">2</span> * $i + <span class="number">1</span>;</span><br><span class="line"> $right = <span class="number">2</span> * $i + <span class="number">2</span>;</span><br><span class="line"> $largest = $i;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> ($left < $len && $arr[$left] > $arr[$largest]) {</span><br><span class="line"> $largest = $left;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> ($right < $len && $arr[$right] > $arr[$largest]) {</span><br><span class="line"> $largest = $right;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> ($largest != $i) {</span><br><span class="line"> swap($arr, $i, $largest);</span><br><span class="line"> heapify($arr, $largest);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">swap</span><span class="params">(&$arr, $i, $j)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> $temp = $arr[$i];</span><br><span class="line"> $arr[$i] = $arr[$j];</span><br><span class="line"> $arr[$j] = $temp;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">heapSort</span><span class="params">($arr)</span> </span>{</span><br><span class="line"> <span class="keyword">global</span> $len;</span><br><span class="line"> $len = count($arr);</span><br><span class="line"> buildMaxHeap($arr);</span><br><span class="line"> <span class="keyword">for</span> ($i = count($arr) - <span class="number">1</span>; $i > <span class="number">0</span>; $i--) {</span><br><span class="line"> swap($arr, <span class="number">0</span>, $i);</span><br><span class="line"> $len--;</span><br><span class="line"> heapify($arr, <span class="number">0</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>堆排序(Heapsort)是指利用堆这种数据结构所设计的一种排序算法。堆积是一个近似完全二叉树的结构,并同时满足堆积的性质:即子结点的键值或索引总是小于(或者大于)它的父节点。堆排序可以说是一种利用堆的概念来排序的选择排序。分为两种方法:</p>
<ol>
<li>大顶堆:
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>计数排序</title>
<link href="http://junjun.vip/2019/07/05/8.countingSort/"/>
<id>http://junjun.vip/2019/07/05/8.countingSort/</id>
<published>2019-07-04T16:00:00.000Z</published>
<updated>2019-07-05T17:33:16.101Z</updated>
<content type="html"><![CDATA[<p>计数排序的核心在于将输入的数据值转化为键存储在额外开辟的数组空间中。作为一种线性时间复杂度的排序,计数排序要求输入的数据必须是有确定范围的整数。</p><h2 id="1-动图演示"><a href="#1-动图演示" class="headerlink" title="1. 动图演示"></a>1. 动图演示</h2><p><img src="/images/sort/countingSort.gif" alt="动图演示"></p><h2 id="2-JavaScript-代码实现"><a href="#2-JavaScript-代码实现" class="headerlink" title="2. JavaScript 代码实现"></a>2. JavaScript 代码实现</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">countingSort</span>(<span class="params">arr, maxValue</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> bucket = <span class="keyword">new</span> <span class="built_in">Array</span>(maxValue+<span class="number">1</span>),</span><br><span class="line"> sortedIndex = <span class="number">0</span>;</span><br><span class="line"> arrLen = arr.length,</span><br><span class="line"> bucketLen = maxValue + <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i < arrLen; i++) {</span><br><span class="line"> <span class="keyword">if</span> (!bucket[arr[i]]) {</span><br><span class="line"> bucket[arr[i]] = <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> bucket[arr[i]]++;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">var</span> j = <span class="number">0</span>; j < bucketLen; j++) {</span><br><span class="line"> <span class="keyword">while</span>(bucket[j] > <span class="number">0</span>) {</span><br><span class="line"> arr[sortedIndex++] = j;</span><br><span class="line"> bucket[j]--;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="3-Python-代码实现"><a href="#3-Python-代码实现" class="headerlink" title="3. Python 代码实现"></a>3. Python 代码实现</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">countingSort</span><span class="params">(arr, maxValue)</span>:</span></span><br><span class="line"> bucketLen = maxValue+<span class="number">1</span></span><br><span class="line"> bucket = [<span class="number">0</span>]*bucketLen</span><br><span class="line"> sortedIndex =<span class="number">0</span></span><br><span class="line"> arrLen = len(arr)</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(arrLen):</span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> bucket[arr[i]]:</span><br><span class="line"> bucket[arr[i]]=<span class="number">0</span></span><br><span class="line"> bucket[arr[i]]+=<span class="number">1</span></span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> range(bucketLen):</span><br><span class="line"> <span class="keyword">while</span> bucket[j]><span class="number">0</span>:</span><br><span class="line"> arr[sortedIndex] = j</span><br><span class="line"> sortedIndex+=<span class="number">1</span></span><br><span class="line"> bucket[j]-=<span class="number">1</span></span><br><span class="line"> <span class="keyword">return</span> arr</span><br></pre></td></tr></table></figure><h2 id="4-Go-代码实现"><a href="#4-Go-代码实现" class="headerlink" title="4. Go 代码实现"></a>4. Go 代码实现</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">countingSort</span><span class="params">(arr []<span class="keyword">int</span>, maxValue <span class="keyword">int</span>)</span> []<span class="title">int</span></span> {</span><br><span class="line">bucketLen := maxValue + <span class="number">1</span></span><br><span class="line">bucket := <span class="built_in">make</span>([]<span class="keyword">int</span>, bucketLen) <span class="comment">// 初始为0的数组</span></span><br><span class="line"></span><br><span class="line">sortedIndex := <span class="number">0</span></span><br><span class="line">length := <span class="built_in">len</span>(arr)</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> i := <span class="number">0</span>; i < length; i++ {</span><br><span class="line">bucket[arr[i]] += <span class="number">1</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> j := <span class="number">0</span>; j < bucketLen; j++ {</span><br><span class="line"><span class="keyword">for</span> bucket[j] > <span class="number">0</span> {</span><br><span class="line">arr[sortedIndex] = j</span><br><span class="line">sortedIndex += <span class="number">1</span></span><br><span class="line">bucket[j] -= <span class="number">1</span></span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">return</span> arr</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="5-Java-代码实现"><a href="#5-Java-代码实现" class="headerlink" title="5. Java 代码实现"></a>5. Java 代码实现</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CountingSort</span> <span class="keyword">implements</span> <span class="title">IArraySort</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">int</span>[] sort(<span class="keyword">int</span>[] sourceArray) <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="comment">// 对 arr 进行拷贝,不改变参数内容</span></span><br><span class="line"> <span class="keyword">int</span>[] arr = Arrays.copyOf(sourceArray, sourceArray.length);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> maxValue = getMaxValue(arr);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> countingSort(arr, maxValue);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">int</span>[] countingSort(<span class="keyword">int</span>[] arr, <span class="keyword">int</span> maxValue) {</span><br><span class="line"> <span class="keyword">int</span> bucketLen = maxValue + <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">int</span>[] bucket = <span class="keyword">new</span> <span class="keyword">int</span>[bucketLen];</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> value : arr) {</span><br><span class="line"> bucket[value]++;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> sortedIndex = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j < bucketLen; j++) {</span><br><span class="line"> <span class="keyword">while</span> (bucket[j] > <span class="number">0</span>) {</span><br><span class="line"> arr[sortedIndex++] = j;</span><br><span class="line"> bucket[j]--;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> arr;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">int</span> <span class="title">getMaxValue</span><span class="params">(<span class="keyword">int</span>[] arr)</span> </span>{</span><br><span class="line"> <span class="keyword">int</span> maxValue = arr[<span class="number">0</span>];</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> value : arr) {</span><br><span class="line"> <span class="keyword">if</span> (maxValue < value) {</span><br><span class="line"> maxValue = value;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> maxValue;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="6-PHP-代码实现"><a href="#6-PHP-代码实现" class="headerlink" title="6. PHP 代码实现"></a>6. PHP 代码实现</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">countingSort</span><span class="params">($arr, $maxValue = null)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span> ($maxValue === <span class="keyword">null</span>) {</span><br><span class="line"> $maxValue = max($arr);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span> ($m = <span class="number">0</span>; $m < $maxValue + <span class="number">1</span>; $m++) {</span><br><span class="line"> $bucket[] = <span class="keyword">null</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> $arrLen = count($arr);</span><br><span class="line"> <span class="keyword">for</span> ($i = <span class="number">0</span>; $i < $arrLen; $i++) {</span><br><span class="line"> <span class="keyword">if</span> (!array_key_exists($arr[$i], $bucket)) {</span><br><span class="line"> $bucket[$arr[$i]] = <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> $bucket[$arr[$i]]++;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> $sortedIndex = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">foreach</span> ($bucket <span class="keyword">as</span> $key => $len) {</span><br><span class="line"> <span class="keyword">if</span> ($len !== <span class="keyword">null</span>) $arr[$sortedIndex++] = $key;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> $arr;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<p>计数排序的核心在于将输入的数据值转化为键存储在额外开辟的数组空间中。作为一种线性时间复杂度的排序,计数排序要求输入的数据必须是有确定范围的整数。</p>
<h2 id="1-动图演示"><a href="#1-动图演示" class="headerlink" title="
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>十大经典排序算法</title>
<link href="http://junjun.vip/2019/07/04/%E5%8D%81%E5%A4%A7%E7%BB%8F%E5%85%B8%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95/"/>
<id>http://junjun.vip/2019/07/04/十大经典排序算法/</id>
<published>2019-07-03T16:00:00.000Z</published>
<updated>2019-07-05T18:04:09.830Z</updated>
<content type="html"><![CDATA[<p>排序算法是《数据结构与算法》中最基本的算法之一。</p><p>排序算法可以分为内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存。常见的内部排序算法有:<strong>插入排序、希尔排序、选择排序、冒泡排序、归并排序、快速排序、堆排序、基数排序</strong>等。用一张图概括:</p><p><img src="/images/sort/sort.png" alt="十大经典排序算法 概览截图"></p><p><strong>关于时间复杂度</strong>:</p><ol><li>平方阶 (O(n2)) 排序<br> 各类简单排序:直接插入、直接选择和冒泡排序。</li><li>线性对数阶 (O(nlog2n)) 排序<br> 快速排序、堆排序和归并排序;</li><li>O(n1+§)) 排序,§ 是介于 0 和 1 之间的常数。<br> 希尔排序</li><li>线性阶 (O(n)) 排序<br> 基数排序,此外还有桶、箱排序。</li></ol><p><strong>关于稳定性</strong>:</p><p>稳定的排序算法:冒泡排序、插入排序、归并排序和基数排序。</p><p>不是稳定的排序算法:选择排序、快速排序、希尔排序、堆排序。</p><p><strong>名词解释</strong>:</p><p><strong>n</strong>:数据规模</p><p><strong>k</strong>:“桶”的个数</p><p><strong>In-place</strong>:占用常数内存,不占用额外内存</p><p><strong>Out-place</strong>:占用额外内存</p><p><strong>稳定性</strong>:排序后 2 个相等键值的顺序和排序之前它们的顺序相同</p><hr><p><strong>GitBook 内容大纲</strong></p><ol><li><a href="../../05/1.bubbleSort">冒泡排序</a></li><li><a href="../../05/2.selectionSort">选择排序</a></li><li><a href="../../05/3.insertionSort">插入排序</a></li><li><a href="../../05/4.shellSort">希尔排序</a></li><li><a href="../../05/5.mergeSort">归并排序</a></li><li><a href="../../05/6.quickSort">快速排序</a></li><li><a href="../../05/7.heapSort">堆排序</a></li><li><a href="../../05/8.countingSort">计数排序</a></li><li><a href="../../05/9.bucketSort">桶排序</a></li><li><a href="../../05/10.radixSort">基数排序</a></li></ol><hr><p>本书内容几乎完全来源于网络。</p><p>开源项目地址:<a href="https://github.com/hustcc/JS-Sorting-Algorithm" target="_blank" rel="noopener">https://github.com/hustcc/JS-Sorting-Algorithm</a>,整理人 <a href="https://github.com/hustcc" target="_blank" rel="noopener">hustcc</a>。</p>]]></content>
<summary type="html">
<p>排序算法是《数据结构与算法》中最基本的算法之一。</p>
<p>排序算法可以分为内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存。常见的内部排序算法有:<strong>插入排序、希尔排
</summary>
<category term="算法" scheme="http://junjun.vip/categories/%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://junjun.vip/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>hexo主题pure使用教程</title>
<link href="http://junjun.vip/2019/07/03/hexo-pure/"/>
<id>http://junjun.vip/2019/07/03/hexo-pure/</id>
<published>2019-07-02T16:00:00.000Z</published>
<updated>2019-07-05T18:07:24.851Z</updated>
<content type="html"><![CDATA[<h1 id="pure"><a href="#pure" class="headerlink" title="pure"></a>pure</h1><p>A brand new default theme for [<a href="https://hexo.io" target="_blank" rel="noopener">Hexo</a>]. </p><p><img src="/images/screenshot/pure.png" alt></p><h2 id="特色"><a href="#特色" class="headerlink" title="特色"></a>特色</h2><ul><li>多语言</li><li>第三方评论框(友言、来必力、gitment、gitalk)</li><li>可展示个人豆瓣书单</li><li>可展示个人github托管项目</li><li>可设置支付宝、微信打赏</li></ul><h2 id="主题颜色"><a href="#主题颜色" class="headerlink" title="主题颜色"></a>主题颜色</h2><p><img src="/images/screenshot/pure-theme-black.png" alt></p><p><img src="/images/screenshot/pure-theme-blue.png" alt></p><p><img src="/images/screenshot/pure-theme-green.png" alt></p><p><img src="/images/screenshot/pure-theme-purple.png" alt></p><h2 id="配置说明"><a href="#配置说明" class="headerlink" title="配置说明"></a>配置说明</h2><p>在 Hexo 中有两份主要的配置文件,其名称都是 _config.yml。 其中,一份位于站点根目录下,主要包含 Hexo 本身的配置;另一份位于主题目录下,这份配置由主题作者提供,主要用于配置主题相关的选项。为了描述方便,在以下说明中,将前者称为站点配置文件, 后者称为主题配置文件</p><h2 id="安装主题"><a href="#安装主题" class="headerlink" title="安装主题"></a>安装主题</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/cofess/hexo-theme-pure.git themes/pure</span><br></pre></td></tr></table></figure><h2 id="更新主题"><a href="#更新主题" class="headerlink" title="更新主题"></a>更新主题</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd themes/pure</span><br><span class="line">git pull</span><br></pre></td></tr></table></figure><h2 id="启用pure主题"><a href="#启用pure主题" class="headerlink" title="启用pure主题"></a>启用pure主题</h2><p>打开站点配置文件,找到theme字段,将其值更改为 pure</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">theme: pure</span><br></pre></td></tr></table></figure><p>到此,主题安装完成。然后启动Hexo服务验证主题是否正确启用。</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo s</span><br></pre></td></tr></table></figure><h2 id="安装插件"><a href="#安装插件" class="headerlink" title="安装插件"></a>安装插件</h2><h3 id="hexo-wordcount"><a href="#hexo-wordcount" class="headerlink" title="hexo-wordcount"></a><a href="https://github.com/willin/hexo-wordcount" target="_blank" rel="noopener">hexo-wordcount</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-wordcount --save</span><br></pre></td></tr></table></figure><h3 id="hexo-generator-json-content"><a href="#hexo-generator-json-content" class="headerlink" title="hexo-generator-json-content"></a><a href="https://github.com/alexbruno/hexo-generator-json-content" target="_blank" rel="noopener">hexo-generator-json-content</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-generator-json-content --save</span><br></pre></td></tr></table></figure><h3 id="hexo-generator-feed"><a href="#hexo-generator-feed" class="headerlink" title="hexo-generator-feed"></a><a href="https://github.com/hexojs/hexo-generator-feed" target="_blank" rel="noopener">hexo-generator-feed</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-generator-feed --save</span><br></pre></td></tr></table></figure><h3 id="hexo-generator-sitemap"><a href="#hexo-generator-sitemap" class="headerlink" title="hexo-generator-sitemap"></a><a href="https://github.com/hexojs/hexo-generator-sitemap" target="_blank" rel="noopener">hexo-generator-sitemap</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-generator-sitemap --save</span><br></pre></td></tr></table></figure><h3 id="hexo-generator-baidu-sitemap"><a href="#hexo-generator-baidu-sitemap" class="headerlink" title="hexo-generator-baidu-sitemap"></a><a href="https://github.com/coneycode/hexo-generator-baidu-sitemap" target="_blank" rel="noopener">hexo-generator-baidu-sitemap</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-generator-baidu-sitemap --save</span><br></pre></td></tr></table></figure><h2 id="主题配置"><a href="#主题配置" class="headerlink" title="主题配置"></a>主题配置</h2><h3 id="设置语言"><a href="#设置语言" class="headerlink" title="设置语言"></a>设置语言</h3><p>打开站点配置文件, 将 language 设置成你所需要的语言。建议明确设置你所需要的语言,可选值对应themes\pure\languages目录下语言文件,简体中文配置如下:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">language: zh-CN</span><br></pre></td></tr></table></figure><h3 id="主题颜色-1"><a href="#主题颜色-1" class="headerlink" title="主题颜色"></a>主题颜色</h3><p>定制了五套颜色,默认白,黑:theme-black,蓝:theme-blue,绿:theme-green,紫:theme-purple</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"># config</span><br><span class="line">config:</span><br><span class="line"> skin: # 主题颜色 theme-black theme-blue theme-green theme-purple</span><br></pre></td></tr></table></figure><h3 id="导航菜单"><a href="#导航菜单" class="headerlink" title="导航菜单"></a>导航菜单</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"># 导航菜单</span><br><span class="line">menu:</span><br><span class="line"> Home: . </span><br><span class="line"> Archives: archives # 归档</span><br><span class="line"> Categories: categories # 分类</span><br><span class="line"> Tags: tags # 标签</span><br><span class="line"> Repository: repository # github repositories</span><br><span class="line"> Books: books # 书单</span><br><span class="line"> Links: links # 友链</span><br><span class="line"> About: about # 关于</span><br><span class="line"></span><br><span class="line"># 导航菜单图标(font awesome)</span><br><span class="line">menu_icons:</span><br><span class="line"> enable: true # 是否启用菜单图标</span><br><span class="line"> home: icon-home-fill</span><br><span class="line"> archives: icon-archives-fill</span><br><span class="line"> categories: icon-folder</span><br><span class="line"> tags: icon-tags</span><br><span class="line"> repository: icon-project</span><br><span class="line"> books: icon-book-fill</span><br><span class="line"> links: icon-friendship</span><br><span class="line"> about: icon-cup-fill</span><br></pre></td></tr></table></figure><h3 id="设置个人信息"><a href="#设置个人信息" class="headerlink" title="设置个人信息"></a>设置个人信息</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">头像在themes\pure\source\images 目录下替换图片即可,捐献的二维码同理。</span><br><span class="line"></span><br><span class="line">个人信息大部分都在 主题配置文件 中设置</span><br></pre></td></tr></table></figure><h3 id="搜索"><a href="#搜索" class="headerlink" title="搜索"></a>搜索</h3><p>主题内置三种站内搜索方式:insight、swiftype、baidu</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># Search</span><br><span class="line">search:</span><br><span class="line"> insight: true # you need to install `hexo-generator-json-content` before using Insight Search</span><br><span class="line"> swiftype: # enter swiftype install key here</span><br><span class="line"> baidu: false # you need to disable other search engines to use Baidu search</span><br></pre></td></tr></table></figure><h3 id="分享"><a href="#分享" class="headerlink" title="分享"></a>分享</h3><p>支持<code>weibo,qq,qzone,wechat,tencent,douban,diandian,facebook,twitter,google,linkedin</code></p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># Share</span><br><span class="line"># weibo,qq,qzone,wechat,tencent,douban,diandian,facebook,twitter,google,linkedin</span><br><span class="line">share:</span><br><span class="line"> enable: true # 是否启用分享</span><br><span class="line"> sites: weibo,qq,wechat,facebook,twitter # PC端显示的分享图标</span><br><span class="line"> mobile_sites: weibo,qq,qzone # 移动端显示的分享图标</span><br></pre></td></tr></table></figure><h3 id="评论"><a href="#评论" class="headerlink" title="评论"></a>评论</h3><p>主题集成了<a href="https://disqus.com/" target="_blank" rel="noopener">disqus</a>、<a href="http://www.uyan.cc/" target="_blank" rel="noopener">友言</a>、<a href="https://livere.com/" target="_blank" rel="noopener">来必力</a>、<a href="https://github.com/imsun/gitment" target="_blank" rel="noopener">gitment</a>、<a href="https://github.com/gitalk/gitalk" target="_blank" rel="noopener">gitalk</a>评论系统,选择其中一种即可</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"># Comment</span><br><span class="line"># Gitment</span><br><span class="line"># Introduction: https://imsun.net/posts/gitment-introduction/</span><br><span class="line">comment:</span><br><span class="line"> type: livere # 启用哪种评论系统</span><br><span class="line"> disqus: # enter disqus shortname here</span><br><span class="line"> youyan: </span><br><span class="line"> uid: *** # enter youyan uid </span><br><span class="line"> livere:</span><br><span class="line"> uid: *** # enter livere uid</span><br><span class="line"> gitment:</span><br><span class="line"> githubID: username</span><br><span class="line"> repo: username.github.io</span><br><span class="line"> ClientID: ***</span><br><span class="line"> ClientSecret: ***</span><br><span class="line"> lazy: false</span><br></pre></td></tr></table></figure><h3 id="文章浏览量统计"><a href="#文章浏览量统计" class="headerlink" title="文章浏览量统计"></a>文章浏览量统计</h3><p>主题内置了不蒜子和leancloud来统计文章浏览量,启用其中之一即可,注意leancloud需要到其官网申请APP ID 和APP Key。</p><p>比如,启用不蒜子来统计文章浏览量,在主题配置文件中把busuanzi设置为true即可:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">pv:</span><br><span class="line"> busuanzi:</span><br><span class="line"> enable: true # 不蒜子统计</span><br></pre></td></tr></table></figure><p>如果不需要第三方来统计浏览量,只需将相应设置改为false即可(设置为false后不会加载第三方JS脚本)</p><h3 id="Github-respostory"><a href="#Github-respostory" class="headerlink" title="Github respostory"></a>Github respostory</h3><p>复制<code>theme/pure/_source/</code> 目录下<code>repository</code>文件夹到<code>blog path/source/</code> 目录下</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"># Github</span><br><span class="line">github: </span><br><span class="line"> username: *** # github username</span><br></pre></td></tr></table></figure><h3 id="豆瓣书单"><a href="#豆瓣书单" class="headerlink" title="豆瓣书单"></a>豆瓣书单</h3><p>复制<code>theme/pure/_source/</code> 目录下<code>books</code>文件夹到<code>blog path/source/</code> 目录下</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># douban 豆瓣书单</span><br><span class="line">douban:</span><br><span class="line"> user: *** # 豆瓣用户名</span><br><span class="line"> start: 0 # 从哪一条记录开始</span><br><span class="line"> count: 100 # 获取豆瓣书单数据条数</span><br></pre></td></tr></table></figure><h3 id="友情链接"><a href="#友情链接" class="headerlink" title="友情链接"></a>友情链接</h3><p>复制<code>theme/pure/_source/</code> 目录下<code>links</code>文件夹到<code>blog path/source/</code> 目录下</p><p>在 hexo 目录下的 source 文件夹内创建一个名为 _data(禁止改名)的文件夹。</p><p>然后在文件内创建一个名为 links.yml 的文件,在其中添加相关数据即可。</p><p>单个友情链接的格式为:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Name:</span><br><span class="line"> link: http://example.com</span><br><span class="line"> avatar: http://example.com/avatar.png</span><br><span class="line"> desc: "这是一个描述"</span><br></pre></td></tr></table></figure><p>添加多个友情链接,我们只需要根据上面的格式重复填写即可。</p><p>. 将 Name 改为友情链接的名字,例如 Cofess。</p><p>. <a href="http://example.com" target="_blank" rel="noopener">http://example.com</a> 为友情链接的地址。</p><p>. <a href="http://example.com/avatar.png" target="_blank" rel="noopener">http://example.com/avatar.png</a> 为友情链接的头像。</p><p>. 这是一个描述 为友情链接描述。</p><h3 id="文章索引目录"><a href="#文章索引目录" class="headerlink" title="文章索引目录"></a>文章索引目录</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">title: 文章标题</span><br><span class="line">categories:</span><br><span class="line"> - 文章分类</span><br><span class="line">tags:</span><br><span class="line"> - 文章标签</span><br><span class="line">toc: true # 是否启用内容索引</span><br></pre></td></tr></table></figure><h3 id="sidebar侧边栏"><a href="#sidebar侧边栏" class="headerlink" title="sidebar侧边栏"></a>sidebar侧边栏</h3><p>文章侧边栏默认为开启状态,如果某篇文章不想开启侧边栏,在文章开头配置加入“sidebar: none”即可:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">title: 文章标题</span><br><span class="line">categories:</span><br><span class="line"> - 文章分类</span><br><span class="line">tags:</span><br><span class="line"> - 文章标签</span><br><span class="line">sidebar: none # 是否启用sidebar侧边栏,none:不启用</span><br></pre></td></tr></table></figure><h2 id="博客优化"><a href="#博客优化" class="headerlink" title="博客优化"></a>博客优化</h2><h3 id="hexo-neat"><a href="#hexo-neat" class="headerlink" title="hexo-neat"></a><a href="https://github.com/rozbo/hexo-neat" target="_blank" rel="noopener">hexo-neat</a></h3><blockquote><p>auto Minify html、js、css and make it neat</p></blockquote><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-neat --save</span><br></pre></td></tr></table></figure><p>在博客配置文件<code>_config.yml</code>中添加</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"># hexo-neat</span><br><span class="line">neat_enable: true</span><br><span class="line">neat_html:</span><br><span class="line"> enable: true</span><br><span class="line"> exclude: </span><br><span class="line">neat_css:</span><br><span class="line"> enable: true</span><br><span class="line"> exclude:</span><br><span class="line"> - '*.min.css'</span><br><span class="line">neat_js:</span><br><span class="line"> enable: true</span><br><span class="line"> mangle: true</span><br><span class="line"> output:</span><br><span class="line"> compress:</span><br><span class="line"> exclude:</span><br><span class="line"> - '*.min.js'</span><br></pre></td></tr></table></figure><h3 id="hexo-baidu-url-submit"><a href="#hexo-baidu-url-submit" class="headerlink" title="hexo-baidu-url-submit"></a><a href="https://github.com/huiwang/hexo-baidu-url-submit" target="_blank" rel="noopener">hexo-baidu-url-submit</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-baidu-url-submit --save</span><br></pre></td></tr></table></figure><h3 id="hexo-translate-title"><a href="#hexo-translate-title" class="headerlink" title="hexo-translate-title"></a><a href="https://github.com/cometlj/hexo-translate-title" target="_blank" rel="noopener">hexo-translate-title</a></h3><blockquote><p>使用Google翻译,百度翻译和有道翻译将Hexo中的汉字标题转成英文标题</p></blockquote><p>安装</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-translate-title --save</span><br></pre></td></tr></table></figure><p>在博客配置文件<code>_config.yml</code>中添加</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">translate_title:</span></span><br><span class="line"><span class="attr"> translate_way:</span> <span class="string">google</span> <span class="comment">#google | baidu | youdao</span></span><br><span class="line"><span class="attr"> youdao_api_key:</span> <span class="string">XXX</span></span><br><span class="line"><span class="attr"> youdao_keyfrom:</span> <span class="string">XXX</span></span><br><span class="line"><span class="attr"> is_need_proxy:</span> <span class="literal">true</span> <span class="comment">#true | false</span></span><br><span class="line"><span class="attr"> proxy_url:</span> <span class="attr">http://localhost:8123</span></span><br></pre></td></tr></table></figure><p><strong>注意</strong>:判断是否需要配置google本地代理,因为我在本地是开启时才能访问google翻译的,如果没有被墙,请将<code>_config.yml</code> 下的<code>is_need_proxy: true</code>改为false。如果设置为true,请设置本地代理地址</p><h2 id="数学公式"><a href="#数学公式" class="headerlink" title="数学公式"></a>数学公式</h2><blockquote><p>Hexo默认使用”hexo-renderer-marked”引擎渲染网页,该引擎会把一些特殊的markdown符号转换为相应的html标签</p></blockquote><h3 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h3><p>解决方案有很多,可以网上搜下,为了节省大家的时间,这里只提供亲身测试过的方法。</p><p>更换Hexo的markdown渲染引擎,<a href="https://github.com/CHENXCHEN/hexo-renderer-markdown-it-plus" target="_blank" rel="noopener">hexo-renderer-markdown-it-plus</a>引擎替换默认的渲染引擎<a href="https://github.com/hexojs/hexo-renderer-marked" target="_blank" rel="noopener">hexo-renderer-marked</a>即可。</p><h3 id="安装hexo-renderer-markdown-it-plus插件"><a href="#安装hexo-renderer-markdown-it-plus插件" class="headerlink" title="安装hexo-renderer-markdown-it-plus插件"></a>安装hexo-renderer-markdown-it-plus插件</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm un hexo-renderer-marked --save</span><br><span class="line">npm i hexo-renderer-markdown-it-plus --save</span><br></pre></td></tr></table></figure><h3 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h3><p>安装插件后,如果未正常渲染LaTeX数学公式,在博客配置文件<code>_config.yml</code>中添加</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">markdown_it_plus:</span><br><span class="line"> highlight: true</span><br><span class="line"> html: true</span><br><span class="line"> xhtmlOut: true</span><br><span class="line"> breaks: true</span><br><span class="line"> langPrefix:</span><br><span class="line"> linkify: true</span><br><span class="line"> typographer:</span><br><span class="line"> quotes: “”‘’</span><br><span class="line"> plugins:</span><br><span class="line"> - plugin:</span><br><span class="line"> name: markdown-it-katex</span><br><span class="line"> enable: true</span><br><span class="line"> - plugin:</span><br><span class="line"> name: markdown-it-mark</span><br><span class="line"> enable: false</span><br></pre></td></tr></table></figure><h3 id="文章启用mathjax"><a href="#文章启用mathjax" class="headerlink" title="文章启用mathjax"></a>文章启用mathjax</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">title: Hello World</span><br><span class="line">mathjax: true</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h1 id="pure"><a href="#pure" class="headerlink" title="pure"></a>pure</h1><p>A brand new default theme for [<a href="https://hexo.io" targe
</summary>
<category term="hexo" scheme="http://junjun.vip/categories/hexo/"/>
<category term="hexo" scheme="http://junjun.vip/tags/hexo/"/>
</entry>
<entry>
<title>hexo命令</title>
<link href="http://junjun.vip/2019/07/03/hello-world/"/>
<id>http://junjun.vip/2019/07/03/hello-world/</id>
<published>2019-07-02T16:00:00.000Z</published>
<updated>2019-07-05T08:35:52.485Z</updated>
<content type="html"><![CDATA[<p>Welcome to <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="noopener">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="noopener">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="noopener">GitHub</a>.</p><h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="noopener">Writing</a></p><h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="noopener">Server</a></p><h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="noopener">Generating</a></p><h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="noopener">Deployment</a></p>]]></content>
<summary type="html">
<p>Welcome to <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>! This is your very first post. Check <a href="https://hexo.
</summary>
<category term="hexo" scheme="http://junjun.vip/categories/hexo/"/>
<category term="hexo" scheme="http://junjun.vip/tags/hexo/"/>
</entry>
</feed>