Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 75cb7d6

Browse files
authored
Update 4.shellSort.md
1 parent 1f7b01b commit 75cb7d6

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

‎4.shellSort.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,19 @@ function shellSort($arr)
148148
## 7. C++ 代码实现
149149

150150
```cpp
151-
void shellSort(vector<int>& nums) {
151+
void shellSort(vector<int>& arr) {
152152
int gap = 1;
153-
while (gap < (int)nums.size() / 3) {
153+
while (gap < (int)arr.size() / 3) {
154154
gap = gap * 3 + 1;
155155
}
156156
for (; gap >= 1; gap /= 3) {
157157
for (int i = 0; i < gap; ++i) {
158-
for (int j = i + gap; j < nums.size(); j += gap) {
159-
for (int k = j; k - gap >= 0 && nums[k] < nums[k - gap]; k -= gap) {
160-
swap(nums[k], nums[k - gap]);
158+
for (int j = i + gap; j < arr.size(); j += gap) {
159+
for (int k = j; k - gap >= 0 && arr[k] < arr[k - gap]; k -= gap) {
160+
swap(arr[k], arr[k - gap]);
161161
}
162162
}
163163
}
164164
}
165165
}
166-
167166
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /