FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
interview/Algorithm/ShellSort.h at master · nativeclass/interview · GitHub
nativeclass
/
interview
Public
forked from
huihut/interview
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
interview
/
Algorithm
/
ShellSort.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
16 lines (16 loc) · 501 Bytes
Breadcrumbs
interview
/
Algorithm
/
ShellSort.h
Copy path
File metadata and controls
16 lines (16 loc) · 501 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//
希尔排序:每一轮按照事先决定的间隔进行插入排序,间隔会依次缩小,最后一次一定要是1。
template
<
typename
T>
void
shell_sort
(T array[],
int
length) {
int
h =
1
;
while
(h < length /
3
) {
h =
3
* h +
1
;
}
while
(h >=
1
) {
for
(
int
i = h; i < length; i++) {
for
(
int
j = i; j >= h && array[j] < array[j - h]; j -= h) {
std::swap
(array[j], array[j - h]);
}
}
h = h /
3
;
}
}
Back
|
FazBrowse Home
|
New Git URL