Skip to content

Commit 4b592a2

Browse files
committed
add merge sort algorithm comment
add merge sort algorithm comment
1 parent 7b6b85c commit 4b592a2

File tree

7 files changed

+93
-5
lines changed

7 files changed

+93
-5
lines changed

5.mergeSort.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
## 4. C++代码实现
3939

4040
```cpp
41+
/*
42+
用迭代器实现归并排序过程
43+
*/
44+
45+
//归并排序合并过程
4146
void merge(vector<int> vec, vector<int>::iterator start, vector<int>::iterator mid, vector<int>::iterator end, vector<int> result)
4247
{
4348
int i = 0;
@@ -66,21 +71,22 @@ void merge(vector<int> vec, vector<int>::iterator start, vector<int>::iterator m
6671
cout << *(start - 1) << endl;
6772
}
6873
}
69-
void mergeSortA(vector<int> vec, vector<int>::iterator start, vector<int>::iterator end, vector<int> result)
74+
//归并排序递归过程
75+
void mergeSortSub(vector<int> vec, vector<int>::iterator start, vector<int>::iterator end, vector<int> result)
7076
{
7177
int mid = 0;
7278
if (end > start)
7379
{
7480
mid = (end - start ) / 2;
7581
//左边排序
76-
mergeSortA(vec, start, start + mid, result);
82+
mergeSortSub(vec, start, start + mid, result);
7783
//右边排序
78-
mergeSortA(vec, start + mid + 1, end, result);
84+
mergeSortSub(vec, start + mid + 1, end, result);
7985
//合并
8086
merge(vec, start, start+mid, end, result);
8187
}
8288
}
83-
89+
//归并排序算法入口
8490
vector<int> AlgorithmSort::mergeSort(vector<int> vec)
8591
{
8692
int len = vec.size();
@@ -92,7 +98,7 @@ vector<int> AlgorithmSort::mergeSort(vector<int> vec)
9298
/*
9399
左边与右边排序,再做归并
94100
*/
95-
mergeSortA(vec, vec.begin(), vec.end()-1, result);
101+
mergeSortSub(vec, vec.begin(), vec.end()-1, result);
96102

97103
return vec;
98104
}

src/java/.classpath

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
14+
</attributes>
15+
</classpathentry>
16+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
17+
<attributes>
18+
<attribute name="maven.pomderived" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
22+
<attributes>
23+
<attribute name="maven.pomderived" value="true"/>
24+
</attributes>
25+
</classpathentry>
26+
<classpathentry kind="src" path="target/generated-sources/annotations">
27+
<attributes>
28+
<attribute name="optional" value="true"/>
29+
<attribute name="maven.pomderived" value="true"/>
30+
<attribute name="ignore_optional_problems" value="true"/>
31+
<attribute name="m2e-apt" value="true"/>
32+
</attributes>
33+
</classpathentry>
34+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
35+
<attributes>
36+
<attribute name="optional" value="true"/>
37+
<attribute name="maven.pomderived" value="true"/>
38+
<attribute name="ignore_optional_problems" value="true"/>
39+
<attribute name="m2e-apt" value="true"/>
40+
<attribute name="test" value="true"/>
41+
</attributes>
42+
</classpathentry>
43+
<classpathentry kind="output" path="target/classes"/>
44+
</classpath>

src/java/.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>sort</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.apt.aptEnabled=false
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3+
org.eclipse.jdt.core.compiler.compliance=1.8
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.processAnnotations=disabled
6+
org.eclipse.jdt.core.compiler.release=disabled
7+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

0 commit comments

Comments
 (0)