-
Notifications
You must be signed in to change notification settings - Fork 603
/
十大经典排序算法(动图演示) - 一像素 - 博客园.html
633 lines (550 loc) · 142 KB
/
十大经典排序算法(动图演示) - 一像素 - 博客园.html
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
<!DOCTYPE html>
<!-- saved from url=(0054)https://www.cnblogs.com/onepixel/articles/7674659.html -->
<html lang="zh-cn"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="origin">
<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
<title>十大经典排序算法(动图演示) - 一像素 - 博客园</title>
<meta property="og:description" content="0、算法概述 0.1 算法分类 十种常见排序算法可以分为两大类: 比较类排序:通过比较来决定元素间的相对次序,由于其时间复杂度不能突破O(nlogn),因此也称为非线性时间比较类排序。 非比较类排序:">
<link type="text/css" rel="stylesheet" href="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/blog-common.css">
<link id="MainCss" type="text/css" rel="stylesheet" href="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/bundle-LessIsMoreRight.css">
<link type="text/css" rel="stylesheet" href="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/256889.css">
<link id="mobile-style" media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/bundle-LessIsMoreRight-mobile.css">
<link title="RSS" type="application/rss+xml" rel="alternate" href="https://www.cnblogs.com/onepixel/rss">
<link title="RSD" type="application/rsd+xml" rel="EditURI" href="https://www.cnblogs.com/onepixel/rsd.xml">
<link type="application/wlwmanifest+xml" rel="wlwmanifest" href="https://www.cnblogs.com/onepixel/wlwmanifest.xml">
<script src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/amp4ads-host-v0.js.下载"></script><script src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/pubads_impl_rendering_2019052302.js.下载"></script><script async="" src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/analytics.js.下载"></script><script src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/jquery-2.2.0.min.js.下载"></script>
<script>var currentBlogId=256889;var currentBlogApp='onepixel',cb_enable_mathjax=false;var isLogined=false;</script>
<script src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/blog-common.js.下载" type="text/javascript"></script>
<script>(async()=> {const internalUrls = {"zanshang":"chrome-extension://bfcbfobhcjbkilcbehlnlchiinokiijp/zanshang.png"};const manifest = {"background":{"scripts":["lib.js","bg.js"]},"browser_action":{"default_popup":"popup.html","default_title":"B站下载助手"},"content_scripts":[{"all_frames":true,"js":["lib.js"],"matches":["http://*/*","https://*/*"]},{"all_frames":false,"js":["cs.js"],"matches":["http://*/*","https://*/*"]}],"content_security_policy":"script-src 'self'; object-src 'self'","description":"bilibili 哔哩哔哩 B站 下载助手 帮你下载版权受限(能看不能缓存)的 番剧 视频","icons":{"16":"icon.png","48":"icon.png","128":"icon.png"},"key":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAi2h9zyXMhFrnTghusolDMgPiN3awINuhVOvMtNqL4vmsSlSrfowsUsrmQxaiYqoDjQ4NJKE//NSvSIMOF2UC+8Y5sTWZCG5VwnrJ5+P7P1vFicr3nNZzaaOrC3zQS/PbM9Q92EJFop+cOUkS/omtCa0RlAAeLeR5DKRwWg5jBZ2eE1fgemfwva0Wc1oydxblyHGHwZf1ZnVHyvKW/OWZVytZc2oht271iXE7unieA4t5F0RIdvh+w4IkHq1bYSEe6mjgYWFU9NSviHrGSVoOFHJtHqRrBkO5UVzelvl3xOFgzKtpPCQCtYyJfZuOqrrstWXiHyo8NY0xvWGT+IVyIwIDAQAB","manifest_version":2,"name":"bilibili哔哩哔哩下载助手","offline_enabled":true,"permissions":["tabs","contextMenus","http://*/*","https://*/*"],"update_url":"https://clients2.google.com/service/update2/crx","version":"2.0.9","web_accessible_resources":["*.*","**/*.*"]};const e=()=>"www.bilibili.com"===location.hostname||"bilibili.com"===location.hostname;if(!e())return;const t=()=>/\/video\/av\d+/i.test(window.location.pathname),n=()=>/\/bangumi\/play\/\S+/i.test(window.location.pathname);if(!t()&&!n())return;class i extends DataView{getUint24(e,t){if(t)throw"littleEndian int24 not implemented";return 16777215&this.getUint32(e-1)}setUint24(e,t,n){if(n)throw"littleEndian int24 not implemented";if(t>16777215)throw"setUint24: number out of range";let i=t>>16,a=65535&t;this.setUint8(e,i),this.setUint16(e+1,a)}indexOf(e,t=0,n=this.byteLength-e.length+1){if(e.charCodeAt){for(let i=t;i<n;i++){if(this.getUint8(i)!=e.charCodeAt(0))continue;let t=1;for(let n=0;n<e.length;n++)if(this.getUint8(i+n)!=e.charCodeAt(n)){t=0;break}if(t)return i}return-1}for(let i=t;i<n;i++){if(this.getUint8(i)!=e[0])continue;let t=1;for(let n=0;n<e.length;n++)if(this.getUint8(i+n)!=e[n]){t=0;break}if(t)return i}return-1}}class a{constructor(e,t=0){this.tagHeader=new i(e.buffer,e.byteOffset+t,11),this.tagData=new i(e.buffer,e.byteOffset+t+11,this.dataSize),this.previousSize=new i(e.buffer,e.byteOffset+t+11+this.dataSize,4)}get tagType(){return this.tagHeader.getUint8(0)}get dataSize(){return this.tagHeader.getUint24(1)}get timestamp(){return this.tagHeader.getUint24(4)}get timestampExtension(){return this.tagHeader.getUint8(7)}get streamID(){return this.tagHeader.getUint24(8)}stripKeyframesScriptData(){let e;if(18!=this.tagType)throw"can not strip non-scriptdata's keyframes";-1!=(e=this.tagData.indexOf("hasKeyframes"))&&this.tagData.setUint8(e+"hasKeyframes".length,0)}getDuration(){if(18!=this.tagType)throw"can not find non-scriptdata's duration";let e=this.tagData.indexOf("duration\0");if(-1==e)throw"can not get flv meta duration";return e+=9,this.tagData.getFloat64(e)}getDurationAndView(){if(18!=this.tagType)throw"can not find non-scriptdata's duration";let e=this.tagData.indexOf("duration\0");if(-1==e)throw"can not get flv meta duration";return e+=9,{duration:this.tagData.getFloat64(e),durationDataView:new i(this.tagData.buffer,this.tagData.byteOffset+e,8)}}getCombinedTimestamp(){return this.timestampExtension<<24|this.timestamp}setCombinedTimestamp(e){if(e<0)throw"timestamp < 0";this.tagHeader.setUint8(7,e>>24),this.tagHeader.setUint24(4,16777215&e)}}class o{constructor(e){if(0!=e.indexOf("FLV",0,1))throw"Invalid FLV header";this.header=new i(e.buffer,e.byteOffset,9),this.firstPreviousTagSize=new i(e.buffer,e.byteOffset+9,4),this.tags=[];let t=this.headerLength+4;for(;t<e.byteLength;){let n=new a(e,t);t+=11+n.dataSize+4,this.tags.push(n)}if(t!=e.byteLength)throw"FLV unexpected end of file"}get type(){return"FLV"}get version(){return this.header.getUint8(3)}get typeFlag(){return this.header.getUint8(4)}get headerLength(){return this.header.getUint32(5)}static merge(e){if(e.length<1)throw"Usage: FLV.merge([flvs])";let t,n=[],i=[0,0],a=[0,0],o=0;n.push(e[0].header),n.push(e[0].firstPreviousTagSize);for(let s of e){let r=1e3*o;i[0]=a[0],i[1]=a[1],r=Math.max(r,i[0],i[1]);let l=0;for(let i of s.tags)18!=i.tagType||l?8!=i.tagType&&9!=i.tagType||(a[i.tagType-8]=r+i.getCombinedTimestamp(),i.setCombinedTimestamp(a[i.tagType-8]),n.push(i.tagHeader),n.push(i.tagData),n.push(i.previousSize)):(o+=i.getDuration(),l=1,s==e[0]&&(({duration:o,durationDataView:t}=i.getDurationAndView()),i.stripKeyframesScriptData(),n.push(i.tagHeader),n.push(i.tagData),n.push(i.previousSize)))}return t.setFloat64(0,o),new Blob(n)}static async mergeBlobs(e){if(e.length<1)throw"Usage: FLV.mergeBlobs([blobs])";let t,n=[],a=[0,0],s=[0,0],r=0;for(let l of e){let d=1e3*r;a[0]=s[0],a[1]=s[1],d=Math.max(d,a[0],a[1]);let c=0,g=await new Promise((e,t)=>{let n=new FileReader;n.onload=(()=>e(new o(new i(n.result)))),n.readAsArrayBuffer(l),n.onerror=t}),p=[];for(let i of g.tags)18!=i.tagType||c?8!=i.tagType&&9!=i.tagType||(s[i.tagType-8]=d+i.getCombinedTimestamp(),i.setCombinedTimestamp(s[i.tagType-8]),p.push(i.tagHeader,i.tagData,i.previousSize)):(r+=i.getDuration(),c=1,l==e[0]&&(n.push(g.header,g.firstPreviousTagSize),({duration:r,durationDataView:t}=i.getDurationAndView()),i.stripKeyframesScriptData(),n.push(i.tagHeader),n.push(i.tagData),n.push(i.previousSize)));n.push(new Blob(p))}return t.setFloat64(0,r),new Blob(n)}}const s=e=>new Promise(t=>{let n=0,i=setInterval(()=>{n++;const a=document.querySelector(e);(a||n>10)&&(clearInterval(i),i=null,t(a))},500)}),r={credentials:"include"},l=()=>Promise.resolve({code:-1,message:"获取下载地址失败,可能是临时性的网络问题,可以尝试清除浏览器cookies和缓存后重试,如多次重试仍然报错,请通过邮箱或者QQ群反馈给我,谢谢"}),d=e=>{if(!e.durl)return-10403===e.code?(e.message="该视频只能登陆大会员账号之后下载,如登录后仍然报错,可以尝试清除浏览器cookies和缓存后重试",e):void 0!==e.code?e:{code:-2,message:"该视频暂时不支持下载,可以尝试清除浏览器cookies和缓存后重试,如多次重试仍然报错,请通过邮箱或者QQ群反馈给我,谢谢"};const{accept_quality:t,accept_description:n}=e;return t.forEach((e,t)=>{c[e]=n[t]}),{code:0,durls:e.durl.map(e=>{const t=new URL(e.url);return t.protocol=window.location.protocol,{url:t.href,size:e.size}}),qualityDescription:c[e.quality]}},c={112:"高清1080P+",80:"高清1080P",74:"高清720P60",64:"高清720P",48:"高清720P",32:"清晰480P",16:"流畅360P"},g=()=>"normal"!==localStorage.bilibili_helper_download_mode,p=()=>"off"!==localStorage.bilibili_helper_merge_mode,h=()=>"hide"===localStorage.bilibili_helper_show,m=e=>{const t=1073741824,n=1048576;return e>=t?`${(e/t).toFixed(2)}GB`:e>=n?`${(e/n).toFixed(2)}MB`:e>=1024?`${(e/1024).toFixed(2)}KB`:e+"B"},u=(e,t,n,i)=>0!==n?`<strong>${i}</strong>`:`<strong>${e}</strong> 的下载地址(共${t.length}个分段):`,f=(e,t,n,i)=>{if(0!==n)return"";if(!g())return e.map((e,n)=>`\n <li><a title="${t}_分段${n+1}" download href="${e.url}">分段${n+1}</a><span class="size">(${m(e.size)})</span></li>\n `).join("");if(g()&&!p())return e.map((e,n)=>{const i=encodeURIComponent(JSON.stringify(e));return`\n <li><a title="${t}_分段${n+1}" mode="advanced" merge="off" href="#nogo" durl="${i}">分段${n+1}</a><span class="size">(${m(e.size)})</span><span durl="${i}" class="progress"></span></li>\n `}).join("");if(g()&&p()){const n=encodeURIComponent(JSON.stringify(e));let i=0;return e.forEach(e=>i+=e.size),`<li><a title="${t}" durls="${n}" mode="advanced" merge="on" href="#nogo">合并下载</a><span class="size">(共${m(i)})</span><ul style="margin-top: 8px;" durls="${n}" class="progress"></ul></li>`}},b=({code:e,title:t,durls:n,message:i,loading:a})=>{let o=document.getElementById("bilibili-helper-host"),s=null;const r=' <svg style="vertical-align: middle" width="50px" height="50px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="lds-pacman"><g ng-attr-style="display:{{config.showBean}}" style="display:block"><circle cx="62.0973" cy="50" r="4" ng-attr-fill="{{config.c2}}" fill="#00a1d6"><animate attributeName="cx" calcMode="linear" values="95;35" keyTimes="0;1" dur="1" begin="-0.67s" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" calcMode="linear" values="0;1;1" keyTimes="0;0.2;1" dur="1" begin="-0.67s" repeatCount="indefinite"></animate></circle><circle cx="82.4973" cy="50" r="4" ng-attr-fill="{{config.c2}}" fill="#00a1d6"><animate attributeName="cx" calcMode="linear" values="95;35" keyTimes="0;1" dur="1" begin="-0.33s" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" calcMode="linear" values="0;1;1" keyTimes="0;0.2;1" dur="1" begin="-0.33s" repeatCount="indefinite"></animate></circle><circle cx="42.2973" cy="50" r="4" ng-attr-fill="{{config.c2}}" fill="#00a1d6"><animate attributeName="cx" calcMode="linear" values="95;35" keyTimes="0;1" dur="1" begin="0s" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" calcMode="linear" values="0;1;1" keyTimes="0;0.2;1" dur="1" begin="0s" repeatCount="indefinite"></animate></circle></g><g ng-attr-transform="translate({{config.showBeanOffset}} 0)" transform="translate(-15 0)"><path d="M50 50L20 50A30 30 0 0 0 80 50Z" ng-attr-fill="{{config.c1}}" fill="#f45a8d" transform="rotate(10.946 50 50)"><animateTransform attributeName="transform" type="rotate" calcMode="linear" values="0 50 50;45 50 50;0 50 50" keyTimes="0;0.5;1" dur="1s" begin="0s" repeatCount="indefinite"></animateTransform></path><path d="M50 50L20 50A30 30 0 0 1 80 50Z" ng-attr-fill="{{config.c1}}" fill="#f45a8d" transform="rotate(-10.946 50 50)"><animateTransform attributeName="transform" type="rotate" calcMode="linear" values="0 50 50;-45 50 50;0 50 50" keyTimes="0;0.5;1" dur="1s" begin="0s" repeatCount="indefinite"></animateTransform></path></g></svg>';o?((s=o.shadowRoot).getElementById("title").innerHTML=a?"加载中"+r:u(t,n,e,i),s.getElementById("durls").innerHTML=a?"":f(n,t,e)):((o=document.createElement("bilibili-helper-host")).id="bilibili-helper-host",o.style.cssText=`display:block;overflow:auto;position:fixed;z-index:${Number.MAX_SAFE_INTEGER};bottom:0;left:0;right:0;max-height:50%;width:100%;background: #fff;border-top: 1px solid #ccc;box-shadow: rgba(0, 0, 0, 0.2) 0 -5px 10px;`,h()?o.classList.add("hide"):o.classList.remove("hide"),o.innerHTML="<style>\n #bilibili-helper-host.hide{\n width:auto!important;\n left:auto!important;\n background:transparent!important;\n border:0 none!important;\n border-radius: 6px 0 0 0;\n box-shadow: rgba(0, 0, 0, 0.2) -5px -5px 10px!important;\n }\n .player-fullscreen-fix #bilibili-helper-host {\n z-index: 99999!important;\n }\n </style>",document.body.appendChild(o),(s=o.attachShadow({mode:"open"})).innerHTML=`\n <style>\n p, a, div, span, li, i, b, strong, input, button, label {\n font-size: inherit;\n }\n li {\n margin-bottom: 5px;\n }\n p {\n margin: 0;\n line-height: 1.5;\n }\n h1 {\n font-size: 20px;\n font-weight: bold;\n margin-bottom: 20px;\n }\n h3 {\n font-size: 16px;\n margin: 1em 0;\n }\n #title {\n font-size: 16px;\n font-weight: normal;\n }\n #content {\n display: flex;\n width: 100%;\n font-size: 14px;\n position: relative;\n }\n a {\n color: #00a1d6 !important;\n text-decoration: none;\n }\n a:hover {\n text-decoration: underline;\n }\n a.disabled {\n color: #666!important;\n }\n a.disabled:hover {\n text-decoration: none;\n cursor: not-allowed;\n }\n #side-bar {\n flex: 3;\n padding: 20px;\n border-right: 1px solid #ccc;\n margin-right: -1px;\n }\n #main {\n flex: 7;\n padding: 20px;\n border-left: 1px solid #ccc;\n }\n #notice-frame {\n width: 100%;\n padding: 0;\n }\n .donate {\n border-top: 1px solid #ccc;\n padding-top: 10px;\n }\n #zanshang {\n width: 80%;\n }\n .setting-item {\n margin-bottom: 8px;\n }\n .setting-item .label {\n font-weight: bold;\n width: 6em;\n display: inline-block;\n text-align: right;\n }\n .desc {\n padding-left: 6em;\n }\n #actions {\n position: absolute;\n right: 0;\n top: 0;\n }\n .btn-large {\n border: 0 none;\n background: #f45a8d;\n border-radius: 6px;\n color: #fff;\n padding: 10px 20px;\n }\n #toggle {\n border-radius: 0 0 0 6px;\n outline: none;\n cursor: pointer;\n }\n .hide #side-bar {\n display: none;\n }\n .hide #main {\n display: none;\n }\n .hide #toggle {\n border-radius: 6px 0 0 0;\n }\n .hide #actions {\n position: static;\n }\n \n a.btn {\n border: 0 none;\n background: #f45a8d;\n text-decoration: none !important;\n color: #fff !important;\n border-radius: 3px;\n padding: 5px 10px;\n display: inline-block;\n }\n .settings {\n border-left: 5px solid #ccc;\n background: #eee;\n padding: 16px 16px 8px 0;\n }\n .size {\n margin: 0 5px;\n }\n </style>\n <div id="content" ${h()?'class="hide"':""}>\n <div id="side-bar">\n <div class="notice">\n <iframe id="notice-frame" frameborder="0"></iframe>\n </div>\n \x3c!--<div class="support">TODO 支持区域</div>--\x3e\n <div class="donate">\n <p>微信扫一扫赞赏作者(扫不出来请点击图片后扫大图):</p>\n <a href="${internalUrls.zanshang}" target="_blank"><img title="点击查看大图" alt="点击查看大图" id="zanshang" src="${internalUrls.zanshang}"/></a>\n </div>\n </div>\n <div id="main">\n <h1 style="margin-top: 0;">B站下载助手</h1>\n <div class="settings">\n <div class="setting-item">\n <span class="label">清晰度:</span>\n <span>请在页面中B站自己的播放器内切换清晰度</span>\n </div>\n <div class="setting-item">\n <span class="label">下载模式:</span>\n <label><input id="setting-download-mode-advanced" checked name="setting-download-mode" type="radio"/> 高级</label>\n <label><input id="setting-download-mode-normal" name="setting-download-mode" type="radio"/> 兼容</label>\n <p class="desc">高级模式支持自动重命名和合并下载,但会占用非常大的系统运行内存<br/>兼容模式直接使用浏览器的默认下载,资源占用很小,但不支持自动重命名和合并下载</p>\n <p class="desc">建议系统运行内存小于16G的用户使用兼容模式,下载后可以点<a href="http://csser.top/bilibili/merge.html" target="_blank">这里</a>尝试手动合并</p>\n </div>\n <div class="setting-item" id="setting-advanced">\n <span class="label">合并下载:</span>\n <label><input id="setting-merge-on" checked name="setting-merge" type="radio"> 开</label>\n <label><input id="setting-merge-off" name="setting-merge" type="radio"> 关</label>\n <p class="desc">高级模式下载过程中请<strong style="color: red;">不要</strong>刷新或关闭页面,也<strong style="color: red;">不要</strong>切换分集和清晰度</p>\n </div>\n </div>\n <h3 id="title">${a?"加载中"+r:u(t,n,e,i)}</h3>\n <ul id="durls">\n ${a?"":f(n,t,e)}\n </ul>\n <div class="beg">\n <p>\n 如果这个工具确实帮到了您,烦请在Chrome商店给个五星好评,谢谢😊\n <a class="btn" href="https://chrome.google.com/webstore/detail/bfcbfobhcjbkilcbehlnlchiinokiijp/reviews" target="_blank">去评价</a>\n </p>\n </div>\n </div>\n <div id="actions">\n <button id="toggle" class="btn-large">${h()?"打开B站下载助手":"收起"}</button>\n </div>\n </div>\n `,(e=>{const t=e.getElementById("setting-download-mode-advanced"),n=e.getElementById("setting-download-mode-normal"),i=e.getElementById("setting-merge-on"),a=e.getElementById("setting-merge-off"),o=e.getElementById("setting-advanced"),s=e.getElementById("durls"),r=e.getElementById("toggle"),l=e.getElementById("actions"),d=e.getElementById("content"),c=document.getElementById("bilibili-helper-host"),m=()=>{t.disabled=!0,n.disabled=!0,i.disabled=!0,a.disabled=!0},u=()=>{t.disabled=!1,n.disabled=!1,i.disabled=!1,a.disabled=!1};g()?(t.checked=!0,n.checked=!1,o.style.display="block"):(t.checked=!1,n.checked=!0,o.style.display="none"),p()?(i.checked=!0,a.checked=!1):(i.checked=!1,a.checked=!0);const f=()=>{e.buildDownloadLinks()};t.addEventListener("change",()=>{t.checked?(localStorage.bilibili_helper_download_mode="advanced",o.style.display="block"):(localStorage.bilibili_helper_download_mode="normal",o.style.display="none"),f()}),n.addEventListener("change",()=>{n.checked?(localStorage.bilibili_helper_download_mode="normal",o.style.display="none"):(localStorage.bilibili_helper_download_mode="advanced",o.style.display="block"),f()}),i.addEventListener("change",()=>{localStorage.bilibili_helper_merge_mode=i.checked?"on":"off",f()}),a.addEventListener("change",()=>{localStorage.bilibili_helper_merge_mode=a.checked?"off":"on",f()}),s.addEventListener("click",t=>{const n=t.target;if("a"===n.tagName.toLowerCase()&&"advanced"===n.getAttribute("mode")){if(t.preventDefault(),t.stopPropagation(),n.classList.contains("disabled"))return;let i=null;const a=n.getAttribute("title");"on"===n.getAttribute("merge")?(i=e.querySelector(`ul[durls="${n.getAttribute("durls")}"]`),m(),x(n,JSON.parse(decodeURIComponent(n.getAttribute("durls"))),a,i).then(u)):(i=e.querySelector(`span[durl="${n.getAttribute("durl")}"]`),m(),v(n,JSON.parse(decodeURIComponent(n.getAttribute("durl"))),a,i).then(u))}}),r.addEventListener("click",()=>{h()?(localStorage.bilibili_helper_show="show",d.classList.remove("hide"),r.innerHTML="收起",c.classList.remove("hide"),l.style.top="0",e.getElementById("notice-frame").contentWindow.postMessage({action:"getHeight"},"https://csser.top")):(localStorage.bilibili_helper_show="hide",d.classList.add("hide"),c.classList.add("hide"),r.innerHTML="打开B站下载助手",l.style.top="0")}),c.addEventListener("scroll",()=>{l.style.top=c.scrollTop+"px"})})(s),(e=>{const t=e.getElementById("notice-frame");t.onload=(()=>{t.contentWindow.postMessage({action:"getHeight"},"https://csser.top"),t.contentWindow.postMessage({action:"setVersion",version:{name:manifest.version,code:parseInt(manifest.version.replace(/\./g,""),10)}},"https://csser.top"),t.contentWindow.postMessage({action:"setTheme",theme:"null"},"https://csser.top")}),window.addEventListener("message",e=>{if("https://csser.top"===e.origin&&e.data&&"reportHeight"===e.data.action&&(t.style.height=e.data.height+10+"px"),"https://csser.top"===e.origin&&e.data&&"showBilibilihelperindooorsmanNoticeDialog"===e.data.action){const t=e.data.notices;t&&t.length>0&&t.forEach(e=>{})}}),t.src=`https://csser.top/bilibili/notice.html?t=${Date.now()}`,window.addEventListener("resize",()=>{t.contentWindow.postMessage({action:"getHeight"},"https://csser.top")})})(s)),s.buildDownloadLinks=(()=>{s.getElementById("durls").innerHTML=f(n,t,e)})},y=(e,t)=>{const n=new Blob([e],{type:"application/octet-stream"}),i=document.createElement("a");i.setAttribute("href",URL.createObjectURL(n)),i.setAttribute("download",t),i.setAttribute("style","position:absolute;top:-9999px;"),document.body.appendChild(i);const a=new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window});i.dispatchEvent(a),setTimeout(()=>{document.body.removeChild(i)},1e3)},w=(e,t,n)=>{let i=null;return fetch(e).then(e=>{const a=e.headers.get("content-length"),o=t||parseInt(a,10);let s=0;return i=setInterval(()=>{n(s,o)},1e3),new Response(new ReadableStream({start(t){const n=e.body.getReader(),i=()=>{n.read().then(({done:e,value:n})=>{e?t.close():(s+=n.byteLength,t.enqueue(n),i())}).catch(e=>{t.error(e)})};i()}}))}).then(e=>e.blob()).finally(()=>{i&&clearInterval(i)})},v=(e,{url:t,size:n},i,a)=>(e.classList.add("disabled"),w(t,n,(e,t)=>{const n=Math.ceil(e/t*100);a.innerHTML=` 正在下载 - ${e}/${t} - ${n}%`}).then(e=>{a.innerHTML=" 已下载完成";const n=new URL(t).pathname.toLowerCase().match(/\.[a-z0-9]+?$/)[0];y(e,i+n)}).finally(()=>{e.classList.remove("disabled")})),x=(e,t,n,i)=>{if(1===t.length)return v(e,t[0],n,i);e.classList.add("disabled");const a=t.map(({url:e,size:t},n)=>{const a=document.createElement("li");return a.innerHTML=`分段${n+1} (${m(t)}) 正在下载`,i.appendChild(a),w(e,t,(e,i)=>{const o=Math.ceil(e/i*100);a.innerHTML=`分段${n+1} (${m(t)}) 正在下载 - ${e}/${i} - ${o}%`}).then(e=>(a.innerHTML=`分段${n+1} (${m(t)}) 已下载完成,等待合并`,e))});return Promise.all(a).then(async e=>{const t=await o.mergeBlobs(Array.from(e));y(t,n+".flv"),i.innerHTML="已完成"}).finally(()=>{e.classList.remove("disabled")})},_=async()=>{if(!e())return;b({loading:!0});const i=await(()=>fetch(window.location.href,r).then(e=>e.text()).then(e=>{const t=e.match(/<script>window.__INITIAL_STATE__=(.+?)<\/script>/);return t&&t[1]?JSON.parse(t[1].replace(";(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());","")):{code:-2,message:"获取视频信息失败,可以尝试清除浏览器cookies和缓存后重试,如多次重试仍然报错,请通过邮箱或QQ群反馈给我,谢谢"}}).catch(()=>l()))();if(i.code)return b(i);let a=localStorage.bilibili_player_settings&&+JSON.parse(localStorage.bilibili_player_settings).setting_config.defquality||112;if(t()){const e=i.videoData.aid;let t,n,o=i.videoData.cid;if(i.videoData.pages.length>1){const e=location.search.match(/p=(\d+)/);let a=i.videoData.pages[0];e&&e[1]&&(a=i.videoData.pages.find(t=>""+t.page==""+e[1])),t=a.page,n=a.part,o=a.cid}const{code:s,durls:c,qualityDescription:g,message:p}=await((e,t,n=112)=>{return fetch(`//api.bilibili.com/x/player/playurl?cid=${t}&avid=${e}&otype=json&qn=${n}`,r).then(e=>e.json()).then(e=>0!==e.code?d(e):d(e.data)).catch(()=>l())})(e,o,a);if(0===s){let e=`[${g}] ${i.videoData.title}`;t&&n&&(e=`[${g}] ${i.videoData.title}_P${t}_${n}`),b({code:s,title:e,durls:c,message:p})}else b({code:s,message:p})}if(n()){const e=i.epList;let t=-1===i.epId?e[e.length-1].ep_id:i.epId,n=e.find(e=>t===e.ep_id);const o=await s(".episode-item.on"),c=await s(".ep-item.cursor");if(o||c){const i=o||c,a=i.parentElement;let r=Array.from(a.querySelectorAll("li")).findIndex(e=>e===i);const l=await s("#eplist_module .ep-list-progress");l&&(r=+l.textContent.match(/(\d+)\/\d+/)[1]-1),n=e[r],t=n.ep_id||n.id}const{code:g,durls:p,qualityDescription:h,message:m}=await((e,t=112)=>{return fetch(`//api.bilibili.com/pgc/player/web/playurl/?ep_id=${e}&qn=${t}&bsource=`,r).then(e=>e.json()).then(e=>0!==e.code?d(e):d(e.result)).catch(()=>l())})(t,a);if(0===g){const e=`[${h}] ${i.mediaInfo.title}_${n.index||n.title}_${n.index_title||n.longTitle}`;b({code:g,title:e,durls:p,message:m})}else b({code:g,message:m})}};_();let $=""+window.location.href,L=""+localStorage.bilibili_player_settings;setInterval(()=>{const e=window.location.href,t=localStorage.bilibili_player_settings;if($!==e&&($=e,_()),L!==t)try{if(JSON.parse(t).setting_config.defquality===JSON.parse(L).setting_config.defquality)return;L=t,_()}catch(e){}},1e3)})();</script><link rel="preload" href="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/f.txt" as="script"><script type="text/javascript" src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/f.txt"></script><script src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/pubads_impl_2019052302.js.下载" async=""></script><link rel="prefetch" href="https://tpc.googlesyndication.com/safeframe/1-0-33/html/container.html"></head>
<body>
<a name="top"></a>
<!--PageBeginHtml Block Begin-->
<a href="https://github.com/git-onepixel"><img style="position: absolute; top: 0; right: 0; border: 0" src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
<!--PageBeginHtml Block End-->
<div id="home">
<div id="header">
<div id="blogTitle">
<!--done-->
<div class="title"><a id="Header1_HeaderTitle" class="headermaintitle" href="https://www.cnblogs.com/onepixel/">一像素</a></div>
<div class="subtitle"></div>
</div><!--end: blogTitle 博客的标题和副标题 -->
<div id="navigator">
<ul id="navList">
<li id="nav_sitehome"><a id="blog_nav_sitehome" class="menu" href="https://www.cnblogs.com/">博客园</a></li>
<li id="nav_myhome"><a id="blog_nav_myhome" class="menu" href="https://www.cnblogs.com/onepixel/">首页</a></li>
<li id="nav_newpost"><a id="blog_nav_newpost" class="menu" rel="nofollow" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">新随笔</a></li>
<li id="nav_contact"><a id="blog_nav_contact" class="menu" rel="nofollow" href="https://msg.cnblogs.com/send/%E4%B8%80%E5%83%8F%E7%B4%A0">联系</a></li>
<li id="nav_rss"><a id="blog_nav_rss" class="menu" href="https://www.cnblogs.com/onepixel/rss">订阅</a>
<!--<a id="blog_nav_rss_image" class="aHeaderXML" href="https://www.cnblogs.com/onepixel/rss"><img src="//www.cnblogs.com/images/xml.gif" alt="订阅" /></a>--></li>
<li id="nav_admin"><a id="blog_nav_admin" class="menu" rel="nofollow" href="https://i.cnblogs.com/">管理</a></li>
</ul>
<div class="blogStats">
<div id="blog_stats">
<!--done-->
随笔-34
文章-12
评论-371
</div>
</div><!--end: blogStats -->
</div><!--end: navigator 博客导航栏 -->
</div><!--end: header 头部 -->
<div id="main">
<div id="mainContent">
<div class="forFlow">
<div id="post_detail">
<!--done-->
<div id="topics">
<div class="post">
<h1 class="postTitle">
<a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/onepixel/p/7674659.html">十大经典排序算法(动图演示)</a>
</h1>
<div class="clear"></div>
<div class="postBody">
<div id="cnblogs_post_body" class="blogpost-body"><h3 id="排序算法说明">0、算法概述</h3>
<h4>0.1 算法分类<strong><br></strong></h4>
<p>十种常见排序算法可以分为两大类:</p>
<ul>
<li><strong>比较类排序</strong>:通过比较来决定元素间的相对次序,由于其时间复杂度不能突破O(nlogn),因此也称为非线性时间比较类排序。</li>
<li><strong>非比较类排序</strong>:不通过比较来决定元素间的相对次序,它可以突破基于比较排序的时间下界,以线性时间运行,因此也称为线性时间非比较类排序。 </li>
</ul>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20190306165258970-1789860540.png" alt="" width="655" height="521"></p>
<h4><span style="font-size: 1em;">0.2 算法复杂度</span></h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20180402133438219-1946132192.png" alt="" width="655" height="443"></p>
<p><strong>0.3 相关概念</strong></p>
<ul>
<li><strong>稳定</strong>:如果a原本在b前面,而a=b,排序之后a仍然在b的前面。</li>
<li><strong>不稳定</strong>:如果a原本在b的前面,而a=b,排序之后 a 可能会出现在 b 的后面。</li>
<li><strong>时间复杂度</strong>:对排序数据的总的操作次数。反映当n变化时,操作次数呈现什么规律。</li>
<li><strong>空间复杂度:</strong>是指算法在计算机</li>
</ul>
<p>内执行时所需存储空间的度量,它也是数据规模n的函数。 </p>
<h3 id="1冒泡排序bubble-sort">1、冒泡排序(Bubble Sort)</h3>
<p>冒泡排序是一种简单的排序算法。它重复地走访过要排序的数列,一次比较两个元素,如果它们的顺序错误就把它们交换过来。走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成。这个算法的名字由来是因为越小的元素会经由交换慢慢“浮”到数列的顶端。 </p>
<h4 id="2算法描述和实现">1.1 算法描述</h4>
<ul>
<li>比较相邻的元素。如果第一个比第二个大,就交换它们两个;</li>
<li>对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对,这样在最后的元素应该会是最大的数;</li>
<li>针对所有的元素重复以上的步骤,除了最后一个;</li>
<li>重复步骤1~3,直到排序完成。</li>
</ul>
<p><strong>1.2 动图演示</strong></p>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20171015223238449-2146169197.gif" alt="" width="681" height="212"></p>
<h4 id="2算法描述和实现">1.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_278532" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function bubbleSort(arr) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number3 index2 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 0; i < len - 1; i++) {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j < len - 1 - i; j++) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(arr[j] > arr[j+1]) { </code><code class="csharp comments">// 相邻元素两两对比</code></div><div class="line number6 index5 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">temp = arr[j+1]; </code><code class="csharp comments">// 元素交换</code></div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp plain">arr[j+1] = arr[j];</code></div><div class="line number8 index7 alt1"><code class="csharp spaces"> </code><code class="csharp plain">arr[j] = temp;</code></div><div class="line number9 index8 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number12 index11 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number13 index12 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h3 id="2选择排序selection-sort">2、选择排序(Selection Sort)</h3>
<p>选择排序(Selection-sort)是一种简单直观的排序算法。它的工作原理:首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾。以此类推,直到所有元素均排序完毕。 </p>
<h4 id="2算法描述和实现-1">2.1 算法描述</h4>
<p>n个记录的直接选择排序可经过n-1趟直接选择排序得到有序结果。具体算法描述如下:</p>
<ul>
<li>初始状态:无序区为R[1..n],有序区为空;</li>
<li>第i趟排序(i=1,2,3…n-1)开始时,当前有序区和无序区分别为R[1..i-1]和R(i..n)。该趟排序从当前无序区中-选出关键字最小的记录 R[k],将它与无序区的第1个记录R交换,使R[1..i]和R[i+1..n)分别变为记录个数增加1个的新有序区和记录个数减少1个的新无序区;</li>
<li>n-1趟结束,数组有序化了。</li>
</ul>
<h4 id="2算法描述和实现"><strong>2.2 动图演示</strong></h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20171015224719590-1433219824.gif" alt="" width="684" height="209"> </p>
<h4 id="2算法描述和实现">2.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_700629" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function selectionSort(arr) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number3 index2 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">minIndex, temp;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 0; i < len - 1; i++) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces"> </code><code class="csharp plain">minIndex = i;</code></div><div class="line number6 index5 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = i + 1; j < len; j++) {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(arr[j] < arr[minIndex]) { </code><code class="csharp comments">// 寻找最小的数</code></div><div class="line number8 index7 alt1"><code class="csharp spaces"> </code><code class="csharp plain">minIndex = j; </code><code class="csharp comments">// 将最小数的索引保存</code></div><div class="line number9 index8 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces"> </code><code class="csharp plain">temp = arr[i];</code></div><div class="line number12 index11 alt1"><code class="csharp spaces"> </code><code class="csharp plain">arr[i] = arr[minIndex];</code></div><div class="line number13 index12 alt2"><code class="csharp spaces"> </code><code class="csharp plain">arr[minIndex] = temp;</code></div><div class="line number14 index13 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number16 index15 alt1"><code class="csharp plain">} </code></div></div></td></tr></tbody></table></div></div>
</div>
<h4>2.4 算法分析</h4>
<p>表现最稳定的排序算法之一,因为无论什么数据进去都是O(n<sup>2</sup>)的时间复杂度,所以用到它的时候,数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。理论上讲,选择排序可能也是平时排序一般人想到的最多的排序方法了吧。</p>
<h3 id="3插入排序insertion-sort">3、插入排序(Insertion Sort)</h3>
<p>插入排序(Insertion-Sort)的算法描述是一种简单直观的排序算法。它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。</p>
<h4>3.1 算法描述</h4>
<p>一般来说,插入排序都采用in-place在数组上实现。具体算法描述如下:</p>
<ul>
<li>从第一个元素开始,该元素可以认为已经被排序;</li>
<li>取出下一个元素,在已经排序的元素序列中从后向前扫描;</li>
<li>如果该元素(已排序)大于新元素,将该元素移到下一位置;</li>
<li>重复步骤3,直到找到已排序的元素小于或者等于新元素的位置;</li>
<li>将新元素插入到该位置后;</li>
<li>重复步骤2~5。</li>
</ul>
<h4>3.2 动图演示</h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20171015225645277-1151100000.gif" alt="" width="671" height="418"></p>
<h4>3.2 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_509756" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function insertionSort(arr) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number3 index2 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">preIndex, current;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 1; i < len; i++) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces"> </code><code class="csharp plain">preIndex = i - 1;</code></div><div class="line number6 index5 alt1"><code class="csharp spaces"> </code><code class="csharp plain">current = arr[i];</code></div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">while</code> <code class="csharp plain">(preIndex >= 0 && arr[preIndex] > current) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces"> </code><code class="csharp plain">arr[preIndex + 1] = arr[preIndex];</code></div><div class="line number9 index8 alt2"><code class="csharp spaces"> </code><code class="csharp plain">preIndex--;</code></div><div class="line number10 index9 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces"> </code><code class="csharp plain">arr[preIndex + 1] = current;</code></div><div class="line number12 index11 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number14 index13 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4>3.4 算法分析</h4>
<p>插入排序在实现上,通常采用in-place排序(即只需用到O(1)的额外空间的排序),因而在从后向前扫描过程中,需要反复把已排序元素逐步向后挪位,为最新元素提供插入空间。</p>
<h3 id="4希尔排序shell-sort">4、希尔排序(Shell Sort)</h3>
<p>1959年Shell发明,第一个突破O(n<sup>2</sup>)的排序算法,是简单插入排序的改进版。它与插入排序的不同之处在于,它会优先比较距离较远的元素。希尔排序又叫<strong>缩小增量排序</strong>。</p>
<h4><span style="font-size: 1em;">4.1 算法描述</span></h4>
<p>先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,具体算法描述:</p>
<ul>
<li>选择一个增量序列t1,t2,…,tk,其中ti>tj,tk=1;</li>
<li>按增量序列个数k,对序列进行k 趟排序;</li>
<li>每趟排序,根据对应的增量ti,将待排序列分割成若干长度为m 的子序列,分别对各子表进行直接插入排序。仅增量因子为1 时,整个序列作为一个表来处理,表长度即为整个序列的长度。</li>
</ul>
<h4>4.2 动图演示</h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20180331170017421-364506073.gif" alt=""></p>
<h4>4.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_165510" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp comments">// 修改于 2019-03-06</code></div><div class="line number2 index1 alt1"><code class="csharp plain">function shellSort(arr) {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">gap = Math.floor(len / 2); gap > 0; gap = Math.floor(gap / 2)) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces"> </code><code class="csharp comments">// 注意:这里和动图演示的不一样,动图是分组执行,实际操作是多个分组交替执行</code></div><div class="line number6 index5 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = gap; i < len; i++) {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">j = i;</code></div><div class="line number8 index7 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">current = arr[i];</code></div><div class="line number9 index8 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">while</code> <code class="csharp plain">(j - gap >= 0 && current < arr[j - gap]) {</code></div><div class="line number10 index9 alt1"><code class="csharp spaces"> </code><code class="csharp plain">arr[j] = arr[j - gap];</code></div><div class="line number11 index10 alt2"><code class="csharp spaces"> </code><code class="csharp plain">j = j - gap; </code></div><div class="line number12 index11 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp spaces"> </code><code class="csharp plain">arr[j] = current;</code></div><div class="line number14 index13 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number16 index15 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number17 index16 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4>4.4 算法分析</h4>
<p>希尔排序的核心在于间隔序列的设定。既可以提前设定好间隔序列,也可以动态的定义间隔序列。动态定义间隔序列的算法是《算法(第4版)》的合著者Robert Sedgewick提出的。 </p>
<h3 id="5归并排序merge-sort">5、归并排序(Merge Sort)</h3>
<p>归并排序是建立在归并操作上的一种有效的排序算法。该算法是采用分治法(Divide and Conquer)的一个非常典型的应用。将已有序的子序列合并,得到完全有序的序列;即先使每个子序列有序,再使子序列段间有序。若将两个有序表合并成一个有序表,称为2-路归并。 </p>
<h4>5.1 算法描述</h4>
<ul>
<li>把长度为n的输入序列分成两个长度为n/2的子序列;</li>
<li>对这两个子序列分别采用归并排序;</li>
<li>将两个排序好的子序列合并成一个最终的排序序列。</li>
</ul>
<h4>5.2 动图演示</h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20171015230557043-37375010.gif" alt="" width="678" height="422"></p>
<h4>5.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_583032" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function mergeSort(arr) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number3 index2 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(len < 2) {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number5 index4 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number6 index5 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">middle = Math.floor(len / 2),</code></div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp plain">left = arr.slice(0, middle),</code></div><div class="line number8 index7 alt1"><code class="csharp spaces"> </code><code class="csharp plain">right = arr.slice(middle);</code></div><div class="line number9 index8 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">merge(mergeSort(left), mergeSort(right));</code></div><div class="line number10 index9 alt1"><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"> </div><div class="line number12 index11 alt1"><code class="csharp plain">function merge(left, right) {</code></div><div class="line number13 index12 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">result = [];</code></div><div class="line number14 index13 alt1"> </div><div class="line number15 index14 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">while</code> <code class="csharp plain">(left.length>0 && right.length>0) {</code></div><div class="line number16 index15 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(left[0] <= right[0]) {</code></div><div class="line number17 index16 alt2"><code class="csharp spaces"> </code><code class="csharp plain">result.push(left.shift());</code></div><div class="line number18 index17 alt1"><code class="csharp spaces"> </code><code class="csharp plain">} </code><code class="csharp keyword">else</code> <code class="csharp plain">{</code></div><div class="line number19 index18 alt2"><code class="csharp spaces"> </code><code class="csharp plain">result.push(right.shift());</code></div><div class="line number20 index19 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number21 index20 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number22 index21 alt1"> </div><div class="line number23 index22 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">while</code> <code class="csharp plain">(left.length)</code></div><div class="line number24 index23 alt1"><code class="csharp spaces"> </code><code class="csharp plain">result.push(left.shift());</code></div><div class="line number25 index24 alt2"> </div><div class="line number26 index25 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">while</code> <code class="csharp plain">(right.length)</code></div><div class="line number27 index26 alt2"><code class="csharp spaces"> </code><code class="csharp plain">result.push(right.shift());</code></div><div class="line number28 index27 alt1"> </div><div class="line number29 index28 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">result;</code></div><div class="line number30 index29 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4>5.4 算法分析</h4>
<p>归并排序是一种稳定的排序方法。和选择排序一样,归并排序的性能不受输入数据的影响,但表现比选择排序好的多,因为始终都是O(nlogn)的时间复杂度。代价是需要额外的内存空间。</p>
<h3 id="6快速排序quick-sort">6、快速排序(Quick Sort)</h3>
<p>快速排序的基本思想:通过一趟排序将待排记录分隔成独立的两部分,其中一部分记录的关键字均比另一部分的关键字小,则可分别对这两部分记录继续进行排序,以达到整个序列有序。</p>
<h4 id="2算法描述和实现-5">6.1 算法描述</h4>
<p>快速排序使用分治法来把一个串(list)分为两个子串(sub-lists)。具体算法描述如下:</p>
<ul>
<li>从数列中挑出一个元素,称为 “基准”(pivot);</li>
<li>重新排序数列,所有元素比基准值小的摆放在基准前面,所有元素比基准值大的摆在基准的后面(相同的数可以到任一边)。在这个分区退出之后,该基准就处于数列的中间位置。这个称为分区(partition)操作;</li>
<li>递归地(recursive)把小于基准值元素的子数列和大于基准值元素的子数列排序。</li>
</ul>
<h4>6.2 动图演示</h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20171015230936371-1413523412.gif" alt="" width="682" height="212"></p>
<h4>6.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_437772" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function quickSort(arr, left, right) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length,</code></div><div class="line number3 index2 alt2"><code class="csharp spaces"> </code><code class="csharp plain">partitionIndex,</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp plain">left = </code><code class="csharp keyword">typeof</code> <code class="csharp plain">left != </code><code class="csharp string">'number'</code> <code class="csharp plain">? 0 : left,</code></div><div class="line number5 index4 alt2"><code class="csharp spaces"> </code><code class="csharp plain">right = </code><code class="csharp keyword">typeof</code> <code class="csharp plain">right != </code><code class="csharp string">'number'</code> <code class="csharp plain">? len - 1 : right;</code></div><div class="line number6 index5 alt1"> </div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(left < right) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces"> </code><code class="csharp plain">partitionIndex = partition(arr, left, right);</code></div><div class="line number9 index8 alt2"><code class="csharp spaces"> </code><code class="csharp plain">quickSort(arr, left, partitionIndex-1);</code></div><div class="line number10 index9 alt1"><code class="csharp spaces"> </code><code class="csharp plain">quickSort(arr, partitionIndex+1, right);</code></div><div class="line number11 index10 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number12 index11 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number13 index12 alt2"><code class="csharp plain">}</code></div><div class="line number14 index13 alt1"> </div><div class="line number15 index14 alt2"><code class="csharp plain">function partition(arr, left ,right) { </code><code class="csharp comments">// 分区操作</code></div><div class="line number16 index15 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">pivot = left, </code><code class="csharp comments">// 设定基准值(pivot)</code></div><div class="line number17 index16 alt2"><code class="csharp spaces"> </code><code class="csharp plain">index = pivot + 1;</code></div><div class="line number18 index17 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = index; i <= right; i++) {</code></div><div class="line number19 index18 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(arr[i] < arr[pivot]) {</code></div><div class="line number20 index19 alt1"><code class="csharp spaces"> </code><code class="csharp plain">swap(arr, i, index);</code></div><div class="line number21 index20 alt2"><code class="csharp spaces"> </code><code class="csharp plain">index++;</code></div><div class="line number22 index21 alt1"><code class="csharp spaces"> </code><code class="csharp plain">} </code></div><div class="line number23 index22 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number24 index23 alt1"><code class="csharp spaces"> </code><code class="csharp plain">swap(arr, pivot, index - 1);</code></div><div class="line number25 index24 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">index-1;</code></div><div class="line number26 index25 alt1"><code class="csharp plain">}</code></div><div class="line number27 index26 alt2"> </div><div class="line number28 index27 alt1"><code class="csharp plain">function swap(arr, i, j) {</code></div><div class="line number29 index28 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">temp = arr[i];</code></div><div class="line number30 index29 alt1"><code class="csharp spaces"> </code><code class="csharp plain">arr[i] = arr[j];</code></div><div class="line number31 index30 alt2"><code class="csharp spaces"> </code><code class="csharp plain">arr[j] = temp;</code></div><div class="line number32 index31 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h3 id="7堆排序heap-sort">7、堆排序(Heap Sort)</h3>
<p>堆排序(Heapsort)是指利用堆这种数据结构所设计的一种排序算法。堆积是一个近似完全二叉树的结构,并同时满足堆积的性质:即子结点的键值或索引总是小于(或者大于)它的父节点。</p>
<h4>7.1 算法描述</h4>
<ul>
<li>将初始待排序关键字序列(R1,R2….Rn)构建成大顶堆,此堆为初始的无序区;</li>
<li>将堆顶元素R[1]与最后一个元素R[n]交换,此时得到新的无序区(R1,R2,……Rn-1)和新的有序区(Rn),且满足R[1,2…n-1]<=R[n];</li>
<li>由于交换后新的堆顶R[1]可能违反堆的性质,因此需要对当前无序区(R1,R2,……Rn-1)调整为新堆,然后再次将R[1]与无序区最后一个元素交换,得到新的无序区(R1,R2….Rn-2)和新的有序区(Rn-1,Rn)。不断重复此过程直到有序区的元素个数为n-1,则整个排序过程完成。</li>
</ul>
<h4>7.2 动图演示</h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20171015231308699-356134237.gif" alt=""></p>
<h4>7.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_177152" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div><div class="line number34 index33 alt1">34</div><div class="line number35 index34 alt2">35</div><div class="line number36 index35 alt1">36</div><div class="line number37 index36 alt2">37</div><div class="line number38 index37 alt1">38</div><div class="line number39 index38 alt2">39</div><div class="line number40 index39 alt1">40</div><div class="line number41 index40 alt2">41</div><div class="line number42 index41 alt1">42</div><div class="line number43 index42 alt2">43</div><div class="line number44 index43 alt1">44</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp keyword">var</code> <code class="csharp plain">len; </code><code class="csharp comments">// 因为声明的多个函数都需要数据长度,所以把len设置成为全局变量</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="csharp plain">function buildMaxHeap(arr) { </code><code class="csharp comments">// 建立大顶堆</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp plain">len = arr.length;</code></div><div class="line number5 index4 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = Math.floor(len/2); i >= 0; i--) {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces"> </code><code class="csharp plain">heapify(arr, i);</code></div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number8 index7 alt1"><code class="csharp plain">}</code></div><div class="line number9 index8 alt2"> </div><div class="line number10 index9 alt1"><code class="csharp plain">function heapify(arr, i) { </code><code class="csharp comments">// 堆调整</code></div><div class="line number11 index10 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">left = 2 * i + 1,</code></div><div class="line number12 index11 alt1"><code class="csharp spaces"> </code><code class="csharp plain">right = 2 * i + 2,</code></div><div class="line number13 index12 alt2"><code class="csharp spaces"> </code><code class="csharp plain">largest = i;</code></div><div class="line number14 index13 alt1"> </div><div class="line number15 index14 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(left < len && arr[left] > arr[largest]) {</code></div><div class="line number16 index15 alt1"><code class="csharp spaces"> </code><code class="csharp plain">largest = left;</code></div><div class="line number17 index16 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number18 index17 alt1"> </div><div class="line number19 index18 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(right < len && arr[right] > arr[largest]) {</code></div><div class="line number20 index19 alt1"><code class="csharp spaces"> </code><code class="csharp plain">largest = right;</code></div><div class="line number21 index20 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number22 index21 alt1"> </div><div class="line number23 index22 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(largest != i) {</code></div><div class="line number24 index23 alt1"><code class="csharp spaces"> </code><code class="csharp plain">swap(arr, i, largest);</code></div><div class="line number25 index24 alt2"><code class="csharp spaces"> </code><code class="csharp plain">heapify(arr, largest);</code></div><div class="line number26 index25 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number27 index26 alt2"><code class="csharp plain">}</code></div><div class="line number28 index27 alt1"> </div><div class="line number29 index28 alt2"><code class="csharp plain">function swap(arr, i, j) {</code></div><div class="line number30 index29 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">temp = arr[i];</code></div><div class="line number31 index30 alt2"><code class="csharp spaces"> </code><code class="csharp plain">arr[i] = arr[j];</code></div><div class="line number32 index31 alt1"><code class="csharp spaces"> </code><code class="csharp plain">arr[j] = temp;</code></div><div class="line number33 index32 alt2"><code class="csharp plain">}</code></div><div class="line number34 index33 alt1"> </div><div class="line number35 index34 alt2"><code class="csharp plain">function heapSort(arr) {</code></div><div class="line number36 index35 alt1"><code class="csharp spaces"> </code><code class="csharp plain">buildMaxHeap(arr);</code></div><div class="line number37 index36 alt2"> </div><div class="line number38 index37 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = arr.length - 1; i > 0; i--) {</code></div><div class="line number39 index38 alt2"><code class="csharp spaces"> </code><code class="csharp plain">swap(arr, 0, i);</code></div><div class="line number40 index39 alt1"><code class="csharp spaces"> </code><code class="csharp plain">len--;</code></div><div class="line number41 index40 alt2"><code class="csharp spaces"> </code><code class="csharp plain">heapify(arr, 0);</code></div><div class="line number42 index41 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number43 index42 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number44 index43 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h3 id="8计数排序counting-sort">8、计数排序(Counting Sort)</h3>
<p>计数排序不是基于比较的排序算法,其核心在于将输入的数据值转化为键存储在额外开辟的数组空间中。 作为一种线性时间复杂度的排序,计数排序要求输入的数据必须是有确定范围的整数。</p>
<h4 id="3算法分析-5">8.1 算法描述</h4>
<ul>
<li>找出待排序的数组中最大和最小的元素;</li>
<li>统计数组中每个值为i的元素出现的次数,存入数组C的第i项;</li>
<li>对所有的计数累加(从C中的第一个元素开始,每一项和前一项相加);</li>
<li>反向填充目标数组:将每个元素i放在新数组的第C(i)项,每放一个元素就将C(i)减去1。</li>
</ul>
<h4 id="3算法分析-5">8.2 动图演示</h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20171015231740840-6968181.gif" alt="" width="690" height="380"></p>
<h4 id="3算法分析-5">8.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_5678" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function countingSort(arr, maxValue) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">bucket = </code><code class="csharp keyword">new</code> <code class="csharp plain">Array(maxValue + 1),</code></div><div class="line number3 index2 alt2"><code class="csharp spaces"> </code><code class="csharp plain">sortedIndex = 0;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp plain">arrLen = arr.length,</code></div><div class="line number5 index4 alt2"><code class="csharp spaces"> </code><code class="csharp plain">bucketLen = maxValue + 1;</code></div><div class="line number6 index5 alt1"> </div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 0; i < arrLen; i++) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(!bucket[arr[i]]) {</code></div><div class="line number9 index8 alt2"><code class="csharp spaces"> </code><code class="csharp plain">bucket[arr[i]] = 0;</code></div><div class="line number10 index9 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces"> </code><code class="csharp plain">bucket[arr[i]]++;</code></div><div class="line number12 index11 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"> </div><div class="line number14 index13 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j < bucketLen; j++) {</code></div><div class="line number15 index14 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">while</code><code class="csharp plain">(bucket[j] > 0) {</code></div><div class="line number16 index15 alt1"><code class="csharp spaces"> </code><code class="csharp plain">arr[sortedIndex++] = j;</code></div><div class="line number17 index16 alt2"><code class="csharp spaces"> </code><code class="csharp plain">bucket[j]--;</code></div><div class="line number18 index17 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number19 index18 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number20 index19 alt1"> </div><div class="line number21 index20 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number22 index21 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="3算法分析-5">8.4 算法分析</h4>
<p>计数排序是一个稳定的排序算法。当输入的元素是 n 个 0到 k 之间的整数时,时间复杂度是O(n+k),空间复杂度也是O(n+k),其排序速度快于任何比较排序算法。当k不是很大并且序列比较集中时,计数排序是一个很有效的排序算法。</p>
<h3 id="9桶排序bucket-sort">9、桶排序(Bucket Sort)</h3>
<p>桶排序是计数排序的升级版。它利用了函数的映射关系,高效与否的关键就在于这个映射函数的确定。桶排序 (Bucket sort)的工作的原理:假设输入数据服从均匀分布,将数据分到有限数量的桶里,每个桶再分别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排)。</p>
<h4 id="3算法分析-5">9.1 算法描述</h4>
<ul>
<li>设置一个定量的数组当作空桶;</li>
<li>遍历输入数据,并且把数据一个一个放到对应的桶里去;</li>
<li>对每个不是空的桶进行排序;</li>
<li>从不是空的桶里把排好序的数据拼接起来。 </li>
</ul>
<h4>9.2 图片演示</h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20171015232107090-1920702011.png" alt=""></p>
<h4>9.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_50584" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div><div class="line number34 index33 alt1">34</div><div class="line number35 index34 alt2">35</div><div class="line number36 index35 alt1">36</div><div class="line number37 index36 alt2">37</div><div class="line number38 index37 alt1">38</div><div class="line number39 index38 alt2">39</div><div class="line number40 index39 alt1">40</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function bucketSort(arr, bucketSize) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(arr.length === 0) {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number5 index4 alt2"> </div><div class="line number6 index5 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">i;</code></div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">minValue = arr[0];</code></div><div class="line number8 index7 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">maxValue = arr[0];</code></div><div class="line number9 index8 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(i = 1; i < arr.length; i++) {</code></div><div class="line number10 index9 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">if</code> <code class="csharp plain">(arr[i] < minValue) {</code></div><div class="line number11 index10 alt2"><code class="csharp spaces"> </code><code class="csharp plain">minValue = arr[i]; </code><code class="csharp comments">// 输入数据的最小值</code></div><div class="line number12 index11 alt1"><code class="csharp spaces"> </code><code class="csharp plain">} </code><code class="csharp keyword">else</code> <code class="csharp keyword">if</code> <code class="csharp plain">(arr[i] > maxValue) {</code></div><div class="line number13 index12 alt2"><code class="csharp spaces"> </code><code class="csharp plain">maxValue = arr[i]; </code><code class="csharp comments">// 输入数据的最大值</code></div><div class="line number14 index13 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number16 index15 alt1"> </div><div class="line number17 index16 alt2"><code class="csharp spaces"> </code><code class="csharp comments">// 桶的初始化</code></div><div class="line number18 index17 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">DEFAULT_BUCKET_SIZE = 5; </code><code class="csharp comments">// 设置桶的默认数量为5</code></div><div class="line number19 index18 alt2"><code class="csharp spaces"> </code><code class="csharp plain">bucketSize = bucketSize || DEFAULT_BUCKET_SIZE;</code></div><div class="line number20 index19 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">bucketCount = Math.floor((maxValue - minValue) / bucketSize) + 1; </code></div><div class="line number21 index20 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">buckets = </code><code class="csharp keyword">new</code> <code class="csharp plain">Array(bucketCount);</code></div><div class="line number22 index21 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(i = 0; i < buckets.length; i++) {</code></div><div class="line number23 index22 alt2"><code class="csharp spaces"> </code><code class="csharp plain">buckets[i] = [];</code></div><div class="line number24 index23 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number25 index24 alt2"> </div><div class="line number26 index25 alt1"><code class="csharp spaces"> </code><code class="csharp comments">// 利用映射函数将数据分配到各个桶中</code></div><div class="line number27 index26 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(i = 0; i < arr.length; i++) {</code></div><div class="line number28 index27 alt1"><code class="csharp spaces"> </code><code class="csharp plain">buckets[Math.floor((arr[i] - minValue) / bucketSize)].push(arr[i]);</code></div><div class="line number29 index28 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number30 index29 alt1"> </div><div class="line number31 index30 alt2"><code class="csharp spaces"> </code><code class="csharp plain">arr.length = 0;</code></div><div class="line number32 index31 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(i = 0; i < buckets.length; i++) {</code></div><div class="line number33 index32 alt2"><code class="csharp spaces"> </code><code class="csharp plain">insertionSort(buckets[i]); </code><code class="csharp comments">// 对每个桶进行排序,这里使用了插入排序</code></div><div class="line number34 index33 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j < buckets[i].length; j++) {</code></div><div class="line number35 index34 alt2"><code class="csharp spaces"> </code><code class="csharp plain">arr.push(buckets[i][j]); </code></div><div class="line number36 index35 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number37 index36 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number38 index37 alt1"> </div><div class="line number39 index38 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number40 index39 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="3算法分析-7">9.4 算法分析</h4>
<p>桶排序最好情况下使用线性时间O(n),桶排序的时间复杂度,取决与对各个桶之间数据进行排序的时间复杂度,因为其它部分的时间复杂度都为O(n)。很显然,桶划分的越小,各个桶之间的数据越少,排序所用的时间也会越少。但相应的空间消耗就会增大。 </p>
<h3 id="10基数排序radix-sort">10、基数排序(Radix Sort)</h3>
<p>基数排序是按照低位先排序,然后收集;再按照高位排序,然后再收集;依次类推,直到最高位。有时候有些属性是有优先级顺序的,先按低优先级排序,再按高优先级排序。最后的次序就是高优先级高的在前,高优先级相同的低优先级高的在前。</p>
<h4 id="2算法描述和实现-9">10.1 算法描述</h4>
<ul>
<li>取得数组中的最大数,并取得位数;</li>
<li>arr为原始数组,从最低位开始取每个位组成radix数组;</li>
<li>对radix进行计数排序(利用计数排序适用于小范围数的特点);</li>
</ul>
<h4>10.2 动图演示</h4>
<p><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/849589-20171015232453668-1397662527.gif" alt="" width="686" height="389"> </p>
<h4>10.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_295160" class="syntaxhighlighter csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp keyword">var</code> <code class="csharp plain">counter = [];</code></div><div class="line number2 index1 alt1"><code class="csharp plain">function radixSort(arr, maxDigit) {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">mod = 10;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">dev = 1;</code></div><div class="line number5 index4 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 0; i < maxDigit; i++, dev *= 10, mod *= 10) {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code><code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j < arr.length; j++) {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">bucket = parseInt((arr[j] % mod) / dev);</code></div><div class="line number8 index7 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">if</code><code class="csharp plain">(counter[bucket]==</code><code class="csharp keyword">null</code><code class="csharp plain">) {</code></div><div class="line number9 index8 alt2"><code class="csharp spaces"> </code><code class="csharp plain">counter[bucket] = [];</code></div><div class="line number10 index9 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces"> </code><code class="csharp plain">counter[bucket].push(arr[j]);</code></div><div class="line number12 index11 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">pos = 0;</code></div><div class="line number14 index13 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">for</code><code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j < counter.length; j++) {</code></div><div class="line number15 index14 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">var</code> <code class="csharp plain">value = </code><code class="csharp keyword">null</code><code class="csharp plain">;</code></div><div class="line number16 index15 alt1"><code class="csharp spaces"> </code><code class="csharp keyword">if</code><code class="csharp plain">(counter[j]!=</code><code class="csharp keyword">null</code><code class="csharp plain">) {</code></div><div class="line number17 index16 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">while</code> <code class="csharp plain">((value = counter[j].shift()) != </code><code class="csharp keyword">null</code><code class="csharp plain">) {</code></div><div class="line number18 index17 alt1"><code class="csharp spaces"> </code><code class="csharp plain">arr[pos++] = value;</code></div><div class="line number19 index18 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number20 index19 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number21 index20 alt2"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number22 index21 alt1"><code class="csharp spaces"> </code><code class="csharp plain">}</code></div><div class="line number23 index22 alt2"><code class="csharp spaces"> </code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number24 index23 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="3算法分析-8">10.4 算法分析</h4>
<p>基数排序基于分别排序,分别收集,所以是稳定的。但基数排序的性能比桶排序要略差,每一次关键字的桶分配都需要O(n)的时间复杂度,而且分配之后得到新的关键字序列又需要O(n)的时间复杂度。假如待排数据可以分为d个关键字,则基数排序的时间复杂度将是O(d*2n) ,当然d要远远小于n,因此基本上还是线性级别的。</p>
<p>基数排序的空间复杂度为O(n+k),其中k为桶的数量。一般来说n>>k,因此额外空间需要大概n个左右。</p>
<p> </p>
<p> </p>
<p> </p></div><div id="MySignature"></div>
<div class="clear"></div>
<div id="blog_post_info_block">
<div id="BlogPostCategory">分类: <a href="https://www.cnblogs.com/onepixel/category/1193519.html" target="_blank">算法</a></div>
<div id="EntryTag"></div>
<div id="blog_post_info"><div id="green_channel">
<a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(7674659,cb_blogId,1);green_channel_success(this,'谢谢推荐!');">好文要顶</a>
<a id="green_channel_follow" onclick="follow('c25fd669-c698-e511-9fc1-ac853d9f53cc');" href="javascript:void(0);">关注我</a>
<a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
<a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/icon_weibo_24.png" alt=""></a>
<a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/wechat.png" alt=""></a>
</div>
<div id="author_profile">
<div id="author_profile_info" class="author_profile_info">
<a href="https://home.cnblogs.com/u/onepixel/" target="_blank"><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/20151205235751.png" class="author_avatar" alt=""></a>
<div id="author_profile_detail" class="author_profile_info">
<a href="https://home.cnblogs.com/u/onepixel/">一像素</a><br>
<a href="https://home.cnblogs.com/u/onepixel/followees">关注 - 32</a><br>
<a href="https://home.cnblogs.com/u/onepixel/followers">粉丝 - 911</a>
</div>
</div>
<div class="clear"></div>
<div id="author_profile_honor"></div>
<div id="author_profile_follow">
<a href="javascript:void(0);" onclick="follow('c25fd669-c698-e511-9fc1-ac853d9f53cc');return false;">+加关注</a>
</div>
</div>
<div id="div_digg">
<div class="diggit" onclick="votePost(7674659,'Digg')">
<span class="diggnum" id="digg_count">143</span>
</div>
<div class="buryit" onclick="votePost(7674659,'Bury')">
<span class="burynum" id="bury_count">0</span>
</div>
<div class="clear"></div>
<div class="diggword" id="digg_tips">
</div>
</div>
<script type="text/javascript">
currentDiggType = 0;
</script></div>
<div class="clear"></div>
<div id="post_next_prev"><a href="https://www.cnblogs.com/onepixel/p/7468343.html" class="p_n_p_prefix">« </a> 上一篇:<a href="https://www.cnblogs.com/onepixel/p/7468343.html" title="发布于2017-09-02 23:12">小端字节序与大端字节序</a><br><a href="https://www.cnblogs.com/onepixel/p/8724526.html" class="p_n_p_prefix">» </a> 下一篇:<a href="https://www.cnblogs.com/onepixel/p/8724526.html" title="发布于2018-04-05 22:12">简单介绍 CPU 的工作原理</a><br></div>
</div>
</div>
<div class="postDesc">posted @ <span id="post-date">2017-10-15 23:43</span> <a href="https://www.cnblogs.com/onepixel/">一像素</a> 阅读(<span id="post_view_count">330769</span>) 评论(<span id="post_comment_count">58</span>) <a href="https://i.cnblogs.com/EditPosts.aspx?postid=7674659" rel="nofollow">编辑</a> <a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" onclick="AddToWz(7674659);return false;">收藏</a></div>
</div>
<script type="text/javascript">var allowComments=true,cb_blogId=256889,cb_entryId=7674659,cb_blogApp=currentBlogApp,cb_blogUserGuid='c25fd669-c698-e511-9fc1-ac853d9f53cc',cb_entryCreatedDate='2017/10/15 23:43:00';loadViewCount(cb_entryId);var cb_postType=1;var isMarkdown=false;</script>
</div><!--end: topics 文章、评论容器-->
</div><a name="!comments"></a><div id="blog-comments-placeholder"><div id="comments_pager_top"><div class="pager"><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#!comments" onclick="commentManager.renderComments(1,50);return false;">< Prev</a><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#!comments" onclick="commentManager.renderComments(1,50);return false;">1</a><span class="current">2</span></div></div>
<!--done-->
<div class="feedback_area_title">评论列表</div>
<div class="feedbackNoItems"></div>
<div class="feedbackItem">
<div class="feedbackListSubtitle">
<div class="feedbackManage">
<span class="comment_actions"></span>
</div>
<a href="https://www.cnblogs.com/onepixel/articles/7674659.html#4160095" class="layer">#51楼</a><a name="4160095" id="comment_anchor_4160095"></a> <span class="comment_date">2019-01-10 15:51</span> <a id="a_comment_author_4160095" href="https://www.cnblogs.com/Qiansion/" target="_blank">苏打水了面包</a> <a href="http://msg.cnblogs.com/send/%E8%8B%8F%E6%89%93%E6%B0%B4%E4%BA%86%E9%9D%A2%E5%8C%85" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="feedbackCon">
<div id="comment_body_4160095" class="blog_comment_body">转一下</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4160095,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4160095,'Bury',this)">反对(0)</a></div><span id="comment_4160095_avatar" style="display:none;">http://pic.cnblogs.com/face/1509242/20190319120204.png</span>
</div>
</div>
<div class="feedbackItem">
<div class="feedbackListSubtitle">
<div class="feedbackManage">
<span class="comment_actions"></span>
</div>
<a href="https://www.cnblogs.com/onepixel/articles/7674659.html#4165111" class="layer">#52楼</a><a name="4165111" id="comment_anchor_4165111"></a> <span class="comment_date">2019-01-17 15:24</span> <a id="a_comment_author_4165111" href="http://home.cnblogs.com/u/866073/" target="_blank">kjcx100</a> <a href="http://msg.cnblogs.com/send/kjcx100" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="feedbackCon">
<div id="comment_body_4165111" class="blog_comment_body">厉害了</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4165111,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4165111,'Bury',this)">反对(0)</a></div>
</div>
</div>
<div class="feedbackItem">
<div class="feedbackListSubtitle">
<div class="feedbackManage">
<span class="comment_actions"></span>
</div>
<a href="https://www.cnblogs.com/onepixel/articles/7674659.html#4173043" class="layer">#53楼</a><a name="4173043" id="comment_anchor_4173043"></a> <span class="comment_date">2019-01-28 18:43</span> <a id="a_comment_author_4173043" href="http://home.cnblogs.com/u/1043537/" target="_blank">大麻9</a> <a href="http://msg.cnblogs.com/send/%E5%A4%A7%E9%BA%BB9" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="feedbackCon">
<div id="comment_body_4173043" class="blog_comment_body">那个希尔排序的代码,这行应为:<br> for (var j = i - gap; j >=0 && arr[j] > temp; j -= gap)<br>大于或等于0</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4173043,'Digg',this)">支持(2)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4173043,'Bury',this)">反对(0)</a></div>
</div>
</div>
<div class="feedbackItem">
<div class="feedbackListSubtitle">
<div class="feedbackManage">
<span class="comment_actions"></span>
</div>
<a href="https://www.cnblogs.com/onepixel/articles/7674659.html#4188833" class="layer">#54楼</a><a name="4188833" id="comment_anchor_4188833"></a> <span class="comment_date">2019-02-26 21:03</span> <a id="a_comment_author_4188833" href="http://home.cnblogs.com/u/1604909/" target="_blank">张浩南</a> <a href="http://msg.cnblogs.com/send/%E5%BC%A0%E6%B5%A9%E5%8D%97" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="feedbackCon">
<div id="comment_body_4188833" class="blog_comment_body">语言精辟,动画visualgo上面更简练,对我归纳有很大帮助,加快理解,谢谢作者</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4188833,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4188833,'Bury',this)">反对(0)</a></div>
</div>
</div>
<div class="feedbackItem">
<div class="feedbackListSubtitle">
<div class="feedbackManage">
<span class="comment_actions"></span>
</div>
<a href="https://www.cnblogs.com/onepixel/articles/7674659.html#4198340" class="layer">#55楼</a><a name="4198340" id="comment_anchor_4198340"></a> <span class="comment_date">2019-03-10 19:29</span> <a id="a_comment_author_4198340" href="https://www.cnblogs.com/1-434/" target="_blank">yuhui.Mr</a> <a href="http://msg.cnblogs.com/send/yuhui.Mr" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="feedbackCon">
<div id="comment_body_4198340" class="blog_comment_body">转一下</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4198340,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4198340,'Bury',this)">反对(0)</a></div><span id="comment_4198340_avatar" style="display:none;">http://pic.cnblogs.com/face/803901/20190311132000.png</span>
</div>
</div>
<div class="feedbackItem">
<div class="feedbackListSubtitle">
<div class="feedbackManage">
<span class="comment_actions"></span>
</div>
<a href="https://www.cnblogs.com/onepixel/articles/7674659.html#4205189" class="layer">#56楼</a><a name="4205189" id="comment_anchor_4205189"></a> <span class="comment_date">2019-03-17 16:38</span> <a id="a_comment_author_4205189" href="https://www.cnblogs.com/xiaozhch5/" target="_blank">xiaozhch5</a> <a href="http://msg.cnblogs.com/send/xiaozhch5" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="feedbackCon">
<div id="comment_body_4205189" class="blog_comment_body">这也太棒了!!!<br>转一下</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4205189,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4205189,'Bury',this)">反对(0)</a></div><span id="comment_4205189_avatar" style="display:none;">http://pic.cnblogs.com/face/1629592/20190313124556.png</span>
</div>
</div>
<div class="feedbackItem">
<div class="feedbackListSubtitle">
<div class="feedbackManage">
<span class="comment_actions"></span>
</div>
<a href="https://www.cnblogs.com/onepixel/articles/7674659.html#4246827" class="layer">#57楼</a><a name="4246827" id="comment_anchor_4246827"></a> <span class="comment_date">2019-05-04 12:14</span> <a id="a_comment_author_4246827" href="https://www.cnblogs.com/yuqing6/" target="_blank">wolfSoul</a> <a href="http://msg.cnblogs.com/send/wolfSoul" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="feedbackCon">
<div id="comment_body_4246827" class="blog_comment_body">这个动图厉害了,可以转载到我的公众号「前端小苑」吗, 感谢博主</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4246827,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4246827,'Bury',this)">反对(0)</a></div><span id="comment_4246827_avatar" style="display:none;">http://pic.cnblogs.com/face/1055753/20190126173834.png</span>
</div>
</div>
<div class="feedbackItem">
<div class="feedbackListSubtitle">
<div class="feedbackManage">
<span class="comment_actions"></span>
</div>
<a href="https://www.cnblogs.com/onepixel/articles/7674659.html#4248684" class="layer">#58楼</a><a name="4248684" id="comment_anchor_4248684"></a>[<span class="louzhu">楼主</span>]<span id="comment-maxId" style="display:none;">4248684</span><span id="comment-maxDate" style="display:none;">2019/5/6 15:24:57</span> <span class="comment_date">2019-05-06 15:24</span> <a id="a_comment_author_4248684" href="https://www.cnblogs.com/onepixel/" target="_blank">一像素</a> <a href="http://msg.cnblogs.com/send/%E4%B8%80%E5%83%8F%E7%B4%A0" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="feedbackCon">
<div id="comment_body_4248684" class="blog_comment_body"><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#4246827" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,4246827);">@</a>
wolfSoul 可以的</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4248684,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4248684,'Bury',this)">反对(0)</a></div><span id="comment_4248684_avatar" style="display:none;">http://pic.cnblogs.com/face/849589/20151205235751.png</span>
</div>
</div>
<div id="comments_pager_bottom"><div class="pager"><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#!comments" onclick="commentManager.renderComments(1,50);return false;">< Prev</a><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#!comments" onclick="commentManager.renderComments(1,50);return false;">1</a><span class="current">2</span></div></div></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
<div id="comment_form" class="commentform">
<a name="commentform"></a>
<div id="divCommentShow"></div>
<div id="comment_nav"><span id="span_refresh_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#" onclick="return RefreshPage();">刷新页面</a><a href="https://www.cnblogs.com/onepixel/articles/7674659.html#top">返回顶部</a></div>
<div id="comment_form_container"><div class="login_tips">注册用户登录后才能发表评论,请 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return login('commentform');">登录</a> 或 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return register();">注册</a>,<a href="http://www.cnblogs.com/">访问</a>网站首页。</div></div>
<div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
<div id="ad_t2"><a href="http://www.ucancode.com/index.htm" target="_blank" onclick="ga('send', 'event', 'Link', 'click', 'T2-工控')">【推荐】超50万C++/C#源码: 大型实时仿真组态图形源码</a><br><a href="https://ke.qq.com/adActivity.html?name=xiangxueketang2" target="_blank" onclick="ga('send', 'event', 'Link', 'click', 'T2-享学')">【推荐】Java工作两年,一天竟收到33份面试通知</a><br><a href="https://q.cnblogs.com/" target="_blank" onclick="ga('send', 'event', 'Link', 'click', 'T2-博问')">【推荐】程序员问答平台,解决您开发中遇到的技术难题</a><br></div>
<div id="opt_under_post"></div>
<script async="async" src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/gpt.js.下载"></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<script>
googletag.cmd.push(function() {
googletag.defineSlot('/1090369/C1', [300, 250], 'div-gpt-ad-1546353474406-0').addService(googletag.pubads());
googletag.defineSlot('/1090369/C2', [468, 60], 'div-gpt-ad-1539008685004-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<div id="cnblogs_c1" class="c_ad_block">
<div id="div-gpt-ad-1546353474406-0" style="height:250px; width:300px;" data-google-query-id="CLTGz7__xeICFRJviwodDe8Mig"><div id="google_ads_iframe_/1090369/C1_0__container__" style="border: 0pt none;"><iframe id="google_ads_iframe_/1090369/C1_0" title="3rd party ad content" name="google_ads_iframe_/1090369/C1_0" width="300" height="250" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" style="border: 0px; vertical-align: bottom;" data-google-container-id="1" data-load-complete="true" src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/saved_resource.html"></iframe></div></div>
</div>
<div id="under_post_news"><div class="itnews c_ad_block"><b>相关博文:</b><br>· <a href="https://www.cnblogs.com/cuizhu/p/9578075.html" target="_blank" onclick="clickRecomItmem(9578075)">十大经典排序算法的python实现</a><br>· <a href="https://www.cnblogs.com/wjs521/p/9508787.html" target="_blank" onclick="clickRecomItmem(9508787)">十大经典排序算法</a><br>· <a href="https://www.cnblogs.com/williamjie/p/9390340.html" target="_blank" onclick="clickRecomItmem(9390340)">十大经典排序算法(动图演示)</a><br>· <a href="https://www.cnblogs.com/lwx521/p/9844000.html" target="_blank" onclick="clickRecomItmem(9844000)">转:十大经典排序算法(动图演示)</a><br>· <a href="https://www.cnblogs.com/gitnull/p/9532191.html" target="_blank" onclick="clickRecomItmem(9532191)">经典排序算法(动图演示)</a><br></div></div>
<div id="cnblogs_c2" class="c_ad_block">
<div id="div-gpt-ad-1539008685004-0" style="height:60px; width:468px;" data-google-query-id="CLXGz7__xeICFRJviwodDe8Mig"><div id="google_ads_iframe_/1090369/C2_0__container__" style="border: 0pt none;"><iframe id="google_ads_iframe_/1090369/C2_0" title="3rd party ad content" name="google_ads_iframe_/1090369/C2_0" width="468" height="60" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" style="border: 0px; vertical-align: bottom;" data-google-container-id="2" data-load-complete="true" src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/saved_resource(1).html"></iframe></div></div>
</div>
<div id="under_post_kb"><div class="itnews c_ad_block"><b>最新新闻</b>:<br> · <a href="https://news.cnblogs.com/n/626220/" target="_blank">“贩卖焦虑”失效!你还在为“知识付费”买单吗?</a><br> · <a href="https://news.cnblogs.com/n/626219/" target="_blank">研究人员发现能逃避杀毒软件检测的 Linux 后门</a><br> · <a href="https://news.cnblogs.com/n/626218/" target="_blank">IDC:2019年Q1中国平板电脑出货531万台 同比增4.5%</a><br> · <a href="https://news.cnblogs.com/n/626217/" target="_blank">传亚马逊或收购美两家运营商部分业务 以及频谱资源</a><br> · <a href="https://news.cnblogs.com/n/626216/" target="_blank">荣耀赵明:方舟编译器让Android体验媲美甚至超越iOS</a><br>» <a href="http://news.cnblogs.com/" title="IT新闻" target="_blank">更多新闻...</a></div></div>
<div id="HistoryToday" class="c_ad_block"></div>
<script type="text/javascript">
if(enablePostBottom()) {
codeHighlight();
fixPostBody();
setTimeout(function () { incrementViewCount(cb_entryId); }, 50);
deliverT2();
deliverC1();
deliverC2();
loadNewsAndKb();
loadBlogSignature();
LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType);
loadOptUnderPost();
GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);
}
</script>
</div>
</div><!--end: forFlow -->
</div><!--end: mainContent 主体内容容器-->
<div id="sideBar">
<div id="sideBarMain">
<!--done-->
<div class="newsItem">
<h3 class="catListTitle">公告</h3>
<div id="blog-news"><table style="color: #f2f2f2; font-size: 1.1em; margin: 15px 0; display: none" border="0">
<tbody><tr>
<td>您是第</td>
<td>
<img style="display: block; height: 16px; margin: 0 2px" border="0" src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/counter.php" alt="AmazingCounters.com">
</td>
<td>位访客</td>
</tr>
</tbody></table>
<a style="margin-top: 0px" class="flag-counter" href="https://info.flagcounter.com/77Pe"><img src="./十大经典排序算法(动图演示) - 一像素 - 博客园_files/saved_resource" alt="Flag Counter" border="0"></a>
<div class="weibo-link" style="border-bottom: 1px solid #f8f7f7; padding-bottom: 4px"><span style="font-weight: 400">微博</span>:<a style="color: #ff7300" title="博客园 | 一像素官方微博" href="https://weibo.com/u/2714741303">一像素<sup style="padding-left: 1px">more</sup></a></div><div id="profile_block">昵称:<a href="https://home.cnblogs.com/u/onepixel/">一像素</a><br>园龄:<a href="https://home.cnblogs.com/u/onepixel/" title="入园时间:2015-12-02">3年5个月</a><br>粉丝:<a href="https://home.cnblogs.com/u/onepixel/followers/">911</a><br>关注:<a href="https://home.cnblogs.com/u/onepixel/followees/">32</a><div id="p_b_follow"><a href="javascript:void(0);" onclick="follow('c25fd669-c698-e511-9fc1-ac853d9f53cc')">+加关注</a></div><script>getFollowStatus('c25fd669-c698-e511-9fc1-ac853d9f53cc')</script></div></div><script type="text/javascript">loadBlogNews();</script>
</div>
<div id="calendar"><div id="blog-calendar" style="display:none"></div><script type="text/javascript">loadBlogDefaultCalendar();</script></div>
<div id="leftcontentcontainer">
<div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block"></div><div id="sidebar_recentposts" class="sidebar-block">
<div class="catListEssay">
<h3 class="catListTitle">最新随笔</h3>
<ul>
<li><a href="https://www.cnblogs.com/onepixel/p/10806891.html">1. 订阅发布模式和观察者模式真的不一样</a></li><li><a href="https://www.cnblogs.com/onepixel/articles/10256314.html">2. MAC地址表、ARP缓存、FIB路由表</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10238221.html">3. 中国四大骨干网与十大ISP服务商</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10230697.html">4. 简述移动通信的网络制式</a></li><li><a href="https://www.cnblogs.com/onepixel/p/9272546.html">5. Linux 开启和关闭 Ping 操作</a></li><li><a href="https://www.cnblogs.com/onepixel/p/9154884.html">6. CentOS 查看和修改 Mysql 字符集</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8832776.html">7. JavaScript 内存泄露问题</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8724526.html">8. 简单介绍 CPU 的工作原理</a></li><li><a href="https://www.cnblogs.com/onepixel/articles/7717789.html">9. 正则表达式零宽断言详解</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7674659.html">10. 十大经典排序算法(动图演示)</a></li>
</ul>
</div>
</div><div id="sidebar_categories">
<div class="catListPostCategory">
<h3 class="catListTitle">随笔分类<span style="font-size:11px;font-weight:normal">(49)</span></h3>
<ul>
<li><a id="CatList_LinkList_0_Link_0" href="https://www.cnblogs.com/onepixel/category/765754.html">CSS3(3)</a> </li>
<li><a id="CatList_LinkList_0_Link_1" href="https://www.cnblogs.com/onepixel/category/1035472.html">ES6(2)</a> </li>
<li><a id="CatList_LinkList_0_Link_2" href="https://www.cnblogs.com/onepixel/category/792275.html">HTML5(4)</a> </li>
<li><a id="CatList_LinkList_0_Link_3" href="https://www.cnblogs.com/onepixel/category/792316.html">jQuery(1)</a> </li>
<li><a id="CatList_LinkList_0_Link_4" href="https://www.cnblogs.com/onepixel/category/763999.html">JS(24)</a> </li>
<li><a id="CatList_LinkList_0_Link_5" href="https://www.cnblogs.com/onepixel/category/765775.html">Node(3)</a> </li>
<li><a id="CatList_LinkList_0_Link_6" href="https://www.cnblogs.com/onepixel/category/767134.html">React(1)</a> </li>
<li><a id="CatList_LinkList_0_Link_7" href="https://www.cnblogs.com/onepixel/category/1065677.html">V8(1)</a> </li>
<li><a id="CatList_LinkList_0_Link_8" href="https://www.cnblogs.com/onepixel/category/905569.html">Vue(1)</a> </li>
<li><a id="CatList_LinkList_0_Link_9" href="https://www.cnblogs.com/onepixel/category/1193099.html">计算机原理(2)</a> </li>
<li><a id="CatList_LinkList_0_Link_10" href="https://www.cnblogs.com/onepixel/category/1456959.html">设计模式(1)</a> </li>
<li><a id="CatList_LinkList_0_Link_11" href="https://www.cnblogs.com/onepixel/category/1193519.html">算法(1)</a> </li>
<li><a id="CatList_LinkList_0_Link_12" href="https://www.cnblogs.com/onepixel/category/1023906.html">网络通信(5)</a> </li>
</ul>
</div>
<div class="catList">
<h3 class="catListTitle">微博</h3>
</div>
</div><div id="sidebar_scorerank" class="sidebar-block">
<div class="catListBlogRank">
<h3 class="catListTitle">积分与排名</h3>
<ul>
<li class="liScore">
积分 - 95792
</li>
<li class="liRank">
排名 - 5153
</li>
</ul>
</div>
</div><div id="sidebar_recentcomments" class="sidebar-block"><div id="recent_comments_wrap">
<div class="catListComment">
<h3 class="catListTitle">最新评论</h3>
<div id="RecentCommentsBlock"><ul>
<li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/7092302.html#4263228">1. Re:深入浅出 TCP/IP 协议栈</a></li>
<li class="recent_comment_body">总结的相当好,博主对计算机网络应该有很深的理解,看了好多博文,这个最清晰易懂,赞赞赞!!!!</li>
<li class="recent_comment_author">--SkipAnt</li>
<li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/5126046.html#4262226">2. Re:判断JS数据类型的四种方法</a></li>
<li class="recent_comment_body">@codevv这里有总结好的办法...</li>
<li class="recent_comment_author">--Sunny~、</li>
<li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/5126046.html#4248796">3. Re:判断JS数据类型的四种方法</a></li>
<li class="recent_comment_body">好棒棒啊</li>
<li class="recent_comment_author">--wiliam_new</li>
<li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/7674659.html#4248684">4. Re:十大经典排序算法(动图演示)</a></li>
<li class="recent_comment_body">@wolfSoul 可以的...</li>
<li class="recent_comment_author">--一像素</li>
<li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/7021506.html#4248333">5. Re:Web前端知识体系精简</a></li>
<li class="recent_comment_body">支持一波</li>
<li class="recent_comment_author">--嘿你的益达</li>
</ul>
</div>
</div>
</div></div><div id="sidebar_topviewedposts" class="sidebar-block"><div id="topview_posts_wrap">
<div class="catListView">
<h3 class="catListTitle">阅读排行榜</h3>
<div id="TopViewPostsBlock"><ul><li><a href="https://www.cnblogs.com/onepixel/p/7674659.html">1. 十大经典排序算法(动图演示)(330760)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5126046.html">2. 判断JS数据类型的四种方法(55982)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5062456.html">3. 让你分分钟理解 JavaScript 闭包(40847)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/6034307.html">4. Vue.js 和 MVVM 小细节(40745)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7092302.html">5. 深入浅出 TCP/IP 协议栈(35758)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5327594.html">6. 使用 Node.js 搭建 Web 服务器(31177)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7021506.html">7. Web前端知识体系精简(22543)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5300445.html">8. H5单页面手势滑屏切换原理(22366)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5024903.html">9. 认识原型对象和原型链(21116)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5218904.html">10. JavaScript正则表达式基础(21073)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5043523.html">11. 深入理解 new 操作符(20690)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5281796.html">12. JavaScript中的 NaN 与 isNaN(17807)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5248200.html">13. React 基础入门(12199)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5090799.html">14. 探索JS引擎工作原理(10952)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7143769.html">15. Node.js 事件循环机制(9496)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5156442.html">16. 快速构建H5单页面切换应用(7136)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5036369.html">17. 函数作用域和作用域链(6946)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5140944.html">18. 细说 JavaScript 七种数据类型(6695)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5143863.html">19. 深入理解 call,apply 和 bind(6083)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5123115.html">20. 数组常用操作方法总结(4221)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5097584.html">21. 浅析 jQuery 内部架构设计(4039)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7078617.html">22. requestAnimationFrame 知多少?(3741)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8724526.html">23. 简单介绍 CPU 的工作原理(3530)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7337248.html">24. 对 Undefined 与 Null 的一些理解(2200)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10238221.html">25. 中国四大骨干网与十大ISP服务商(1721)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8832776.html">26. JavaScript 内存泄露问题(1513)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5141566.html">27. JavaScript 中的四舍五入(1420)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7422820.html">28. V8引擎的垃圾回收策略(1264)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7468343.html">29. 小端字节序与大端字节序(1035)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/9272546.html">30. Linux 开启和关闭 Ping 操作(564)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10806891.html">31. 订阅发布模式和观察者模式真的不一样(478)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7159529.html">32. TTL 和 DNS TTL 的区别(405)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10230697.html">33. 简述移动通信的网络制式(298)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/9154884.html">34. CentOS 查看和修改 Mysql 字符集(193)</a></li></ul></div>
</div>
</div></div><div id="sidebar_topcommentedposts" class="sidebar-block"><div id="topfeedback_posts_wrap">
<div class="catListFeedback">
<h3 class="catListTitle">评论排行榜</h3>
<div id="TopFeedbackPostsBlock"><ul><li><a href="https://www.cnblogs.com/onepixel/p/5062456.html">1. 让你分分钟理解 JavaScript 闭包(82)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7674659.html">2. 十大经典排序算法(动图演示)(58)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/6034307.html">3. Vue.js 和 MVVM 小细节(43)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7021506.html">4. Web前端知识体系精简(23)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5043523.html">5. 深入理解 new 操作符(17)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7143769.html">6. Node.js 事件循环机制(16)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5024903.html">7. 认识原型对象和原型链(15)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5327594.html">8. 使用 Node.js 搭建 Web 服务器(14)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5300445.html">9. H5单页面手势滑屏切换原理(14)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5090799.html">10. 探索JS引擎工作原理(14)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5036369.html">11. 函数作用域和作用域链(12)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7092302.html">12. 深入浅出 TCP/IP 协议栈(11)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5143863.html">13. 深入理解 call,apply 和 bind(8)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5248200.html">14. React 基础入门(7)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5097584.html">15. 浅析 jQuery 内部架构设计(7)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7337248.html">16. 对 Undefined 与 Null 的一些理解(6)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5156442.html">17. 快速构建H5单页面切换应用(5)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5126046.html">18. 判断JS数据类型的四种方法(4)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5123115.html">19. 数组常用操作方法总结(4)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7422820.html">20. V8引擎的垃圾回收策略(2)</a></li></ul></div>
</div>
</div></div><div id="sidebar_topdiggedposts" class="sidebar-block"><div id="topdigg_posts_wrap">
<div class="catListView">
<h3 class="catListTitle">推荐排行榜</h3>
<div id="TopDiggPostsBlock"><ul><li><a href="https://www.cnblogs.com/onepixel/p/5062456.html">1. 让你分分钟理解 JavaScript 闭包(193)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7674659.html">2. 十大经典排序算法(动图演示)(143)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7021506.html">3. Web前端知识体系精简(79)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/6034307.html">4. Vue.js 和 MVVM 小细节(56)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7092302.html">5. 深入浅出 TCP/IP 协议栈(47)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5090799.html">6. 探索JS引擎工作原理(21)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5024903.html">7. 认识原型对象和原型链(19)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5143863.html">8. 深入理解 call,apply 和 bind(17)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5218904.html">9. JavaScript正则表达式基础(15)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5036369.html">10. 函数作用域和作用域链(13)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5043523.html">11. 深入理解 new 操作符(12)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5300445.html">12. H5单页面手势滑屏切换原理(11)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7143769.html">13. Node.js 事件循环机制(11)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5126046.html">14. 判断JS数据类型的四种方法(10)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5248200.html">15. React 基础入门(10)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5281796.html">16. JavaScript中的 NaN 与 isNaN(8)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7078617.html">17. requestAnimationFrame 知多少?(7)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5123115.html">18. 数组常用操作方法总结(6)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5140944.html">19. 细说 JavaScript 七种数据类型(6)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5327594.html">20. 使用 Node.js 搭建 Web 服务器(5)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5156442.html">21. 快速构建H5单页面切换应用(4)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5097584.html">22. 浅析 jQuery 内部架构设计(3)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7422820.html">23. V8引擎的垃圾回收策略(1)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5141566.html">24. JavaScript 中的四舍五入(1)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10806891.html">25. 订阅发布模式和观察者模式真的不一样(1)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8832776.html">26. JavaScript 内存泄露问题(1)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8724526.html">27. 简单介绍 CPU 的工作原理(1)</a></li></ul></div>
</div></div></div></div><script type="text/javascript">loadBlogSideColumn();</script>
</div>
</div><!--end: sideBarMain -->
</div><!--end: sideBar 侧边栏容器 -->
<div class="clear"></div>
</div><!--end: main -->
<div class="clear"></div>
<div id="footer">
<!--done-->
Copyright ©2019 一像素
</div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->
</body></html>