Skip to content

Commit

Permalink
array: Add insertion sort
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Jun 30, 2024
1 parent b89132f commit 0424787
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sort/benches/bubble_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn criterion_benchmark(c: &mut Criterion) {
for exp in 1..5 {
let len: usize = 2 * 10_usize.pow(exp);
let arr = random_ints(len).expect("Failed to generate random integers");
let title1 = format!("std_sort {len}");
let title1 = format!("std_sort_for_bubble_sort {len}");
let title2 = format!("bubble_sort {len}");
let title3 = format!("bubble_sort_recursive {len}");
let mut arr_sorted = arr.clone();
Expand Down
2 changes: 1 addition & 1 deletion sort/benches/insertion_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn criterion_benchmark(c: &mut Criterion) {
for exp in 1..5 {
let len: usize = 2 * 10_usize.pow(exp);
let arr = random_ints(len).expect("Failed to generate random integers");
let title1 = format!("std_sort {len}");
let title1 = format!("std_sort_for_insertion_sort {len}");
let title2 = format!("insertion_sort {len}");

c.bench_function(&title1, |b| b.iter(|| {
Expand Down
2 changes: 1 addition & 1 deletion sort/benches/selection_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn criterion_benchmark(c: &mut Criterion) {
for exp in 1..5 {
let len: usize = 2 * 10_usize.pow(exp);
let arr = random_ints(len).expect("Failed to generate random integers");
let title1 = format!("std_sort {len}");
let title1 = format!("std_sort_for_selection_sort {len}");
let title2 = format!("selection_sort {len}");
let title3 = format!("selection_sort_recursive {len}");
let title4 = format!("selection_sort_min_max {len}");
Expand Down
9 changes: 1 addition & 8 deletions sort/src/insertion_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
// Use of this source is governed by General Public License that can be
// found in the LICENSE file.

/// Place one element at a time, inserting each into its proper place.
///
/// The elements to the left of the current index are in sorted order during
/// the sort, but they are not in their final positions, as they may have to
/// be moved to make room for smaller elements later.
///
/// 其思路是, 先将前 i 个元素调整为增序的, 随着 i 从 0 增大到 n, 整个序列
/// 就变得是增序了.
/// 其思路是, 先将前 i 个元素调整为增序的, 随着 i 从 0 增大到 n, 整个序列就变得是增序了.
pub fn insertion_sort<T>(list: &mut [T])
where
T: PartialOrd,
Expand Down
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- [双链表](list/double.md)
- [链表排序 Sort](list/sort/index.md)
- [冒泡排序 Bubble Sort](list/sort/bubble-sort.md)
- [插入排序 Insertion Sort](list/sort/insertion-sort.md)
- [选择排序 Selection Sort](list/sort/selection-sort.md)
- [标准库中 List 的实现](list/impl-oflist.md)
- [跳跃表 SkipList](list/skiplist/index.md)
Expand Down
42 changes: 42 additions & 0 deletions src/array/sort/assets/insertion-sort-pass1.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<mxfile host="Electron" modified="2024-06-30T09:15:20.913Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.2.5 Chrome/120.0.6099.109 Electron/28.1.0 Safari/537.36" etag="qpU8scNtGJk4V5-bdleu" version="24.2.5" type="device">
<diagram name="Page-1" id="LznCcgv3BS2J9Vq8wZ48">
<mxGraphModel dx="1434" dy="835" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="2uTVPKC6mBXRzxm8aPr7-0" />
<mxCell id="2uTVPKC6mBXRzxm8aPr7-1" parent="2uTVPKC6mBXRzxm8aPr7-0" />
<mxCell id="Btw7lg7nnHDqA9ZqbLAq-6" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;entryX=0.5;entryY=1;entryDx=0;entryDy=0;exitX=0.5;exitY=1;exitDx=0;exitDy=0;startArrow=block;startFill=1;" parent="2uTVPKC6mBXRzxm8aPr7-1" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="260" y="360" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="Btw7lg7nnHDqA9ZqbLAq-7" value="9" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="200" y="280" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-22" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="2uTVPKC6mBXRzxm8aPr7-1" source="Btw7lg7nnHDqA9ZqbLAq-8" target="Btw7lg7nnHDqA9ZqbLAq-7" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Btw7lg7nnHDqA9ZqbLAq-8" value="4" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="240" y="280" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="Btw7lg7nnHDqA9ZqbLAq-10" value="1" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="280" y="280" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="Btw7lg7nnHDqA9ZqbLAq-11" value="7" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="320" y="280" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-0" value="4" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="200" y="360" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-1" value="9" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#82b366;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#d5e8d4;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="240" y="360" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-3" value="1" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="280" y="360" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-4" value="7" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="320" y="360" width="40" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
3 changes: 3 additions & 0 deletions src/array/sort/assets/insertion-sort-pass1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions src/array/sort/assets/insertion-sort-pass2.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<mxfile host="Electron" modified="2024-06-30T09:14:56.279Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.2.5 Chrome/120.0.6099.109 Electron/28.1.0 Safari/537.36" etag="3pAqGmCphi-HPMzVeFCf" version="24.2.5" type="device">
<diagram name="Page-1" id="LznCcgv3BS2J9Vq8wZ48">
<mxGraphModel dx="1434" dy="835" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="2uTVPKC6mBXRzxm8aPr7-0" />
<mxCell id="2uTVPKC6mBXRzxm8aPr7-1" parent="2uTVPKC6mBXRzxm8aPr7-0" />
<mxCell id="Btw7lg7nnHDqA9ZqbLAq-6" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;entryX=0.5;entryY=1;entryDx=0;entryDy=0;exitX=0.5;exitY=1;exitDx=0;exitDy=0;startArrow=block;startFill=1;" parent="2uTVPKC6mBXRzxm8aPr7-1" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="260" y="360" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-22" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="2uTVPKC6mBXRzxm8aPr7-1" source="Btw7lg7nnHDqA9ZqbLAq-8" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="220" y="320" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-18" value="4" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="200" y="360" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-19" value="9" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="240" y="360" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-23" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="2uTVPKC6mBXRzxm8aPr7-1" source="_szoXQRxT4SYV6xH7jGY-20" target="_szoXQRxT4SYV6xH7jGY-19" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-20" value="1" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="280" y="360" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-21" value="7" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="320" y="360" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-25" value="4" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="200" y="440" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-30" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="2uTVPKC6mBXRzxm8aPr7-1" source="_szoXQRxT4SYV6xH7jGY-26" target="_szoXQRxT4SYV6xH7jGY-25" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-26" value="1" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="240" y="440" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-28" value="9" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="280" y="440" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-29" value="7" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="320" y="440" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-31" value="1" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#82b366;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#d5e8d4;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="200" y="520" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-33" value="4" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="240" y="520" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-34" value="9" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="280" y="520" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-35" value="7" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" parent="2uTVPKC6mBXRzxm8aPr7-1" vertex="1">
<mxGeometry x="320" y="520" width="40" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
3 changes: 3 additions & 0 deletions src/array/sort/assets/insertion-sort-pass2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions src/array/sort/assets/insertion-sort-pass3.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<mxfile host="Electron" modified="2024-06-30T09:14:18.919Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.2.5 Chrome/120.0.6099.109 Electron/28.1.0 Safari/537.36" etag="UkOe6mJ941FD1Csg6h7D" version="24.2.5" type="device">
<diagram name="Page-1" id="LznCcgv3BS2J9Vq8wZ48">
<mxGraphModel dx="1434" dy="835" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="2uTVPKC6mBXRzxm8aPr7-0" />
<mxCell id="2uTVPKC6mBXRzxm8aPr7-1" parent="2uTVPKC6mBXRzxm8aPr7-0" />
<mxCell id="Btw7lg7nnHDqA9ZqbLAq-6" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;entryX=0.5;entryY=1;entryDx=0;entryDy=0;exitX=0.5;exitY=1;exitDx=0;exitDy=0;startArrow=block;startFill=1;" parent="2uTVPKC6mBXRzxm8aPr7-1" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="260" y="360" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-39" value="1" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="2uTVPKC6mBXRzxm8aPr7-1">
<mxGeometry x="200" y="440" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-40" value="4" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="2uTVPKC6mBXRzxm8aPr7-1">
<mxGeometry x="240" y="440" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-41" value="9" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" vertex="1" parent="2uTVPKC6mBXRzxm8aPr7-1">
<mxGeometry x="280" y="440" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-43" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="2uTVPKC6mBXRzxm8aPr7-1" source="_szoXQRxT4SYV6xH7jGY-42" target="_szoXQRxT4SYV6xH7jGY-41">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-42" value="7" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" vertex="1" parent="2uTVPKC6mBXRzxm8aPr7-1">
<mxGeometry x="320" y="440" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-44" value="1" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="2uTVPKC6mBXRzxm8aPr7-1">
<mxGeometry x="200" y="520" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-45" value="4" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="2uTVPKC6mBXRzxm8aPr7-1">
<mxGeometry x="240" y="520" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-46" value="7" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#82b366;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#d5e8d4;" vertex="1" parent="2uTVPKC6mBXRzxm8aPr7-1">
<mxGeometry x="280" y="520" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="_szoXQRxT4SYV6xH7jGY-48" value="9" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="2uTVPKC6mBXRzxm8aPr7-1">
<mxGeometry x="320" y="520" width="40" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
3 changes: 3 additions & 0 deletions src/array/sort/assets/insertion-sort-pass3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/array/sort/assets/insertion_sort.rs
2 changes: 2 additions & 0 deletions src/array/sort/bubble-sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
2. 将最大的元素移到数组最右侧
3. 递归调用冒泡排序, 但忽略数组的最右侧元素

递归形式的冒泡排序算法需要额外占用 `O(n)` 的内存空间, 用于递归函数调用栈.

```rust
{{#include assets/bubble_sort.rs:29:55}}
```
Expand Down
Loading

0 comments on commit 0424787

Please sign in to comment.