Skip to content

Commit 116722e

Browse files
Merge pull request #538 from Shubham-Khetan-2005/main
ShellSort - C++
2 parents 1b515c2 + 16311ef commit 116722e

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

.vscode/c_cpp_properties.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"configurations": [
33
{
4-
"name": "windows-gcc-x86",
4+
"name": "macos-gcc-arm64",
55
"includePath": [
66
"${workspaceFolder}/**"
77
],
8-
"compilerPath": "C:/MinGW/bin/gcc.exe",
8+
"compilerPath": "/Users/shubham/bin/gcc",
99
"cStandard": "${default}",
1010
"cppStandard": "${default}",
11-
"intelliSenseMode": "windows-gcc-x86",
11+
"intelliSenseMode": "macos-gcc-arm64",
1212
"compilerArgs": [
1313
""
1414
]

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"C_Cpp_Runner.debuggerPath": "gdb",
55
"C_Cpp_Runner.cStandard": "",
66
"C_Cpp_Runner.cppStandard": "",
7-
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
7+
"C_Cpp_Runner.msvcBatchPath": "",
88
"C_Cpp_Runner.useMsvc": false,
99
"C_Cpp_Runner.warnings": [
1010
"-Wall",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
void shellSort(vector<int>& arr) {
5+
int n = arr.size();
6+
for (int gap = n / 2; gap > 0; gap /= 2) {
7+
for (int i = gap; i < n; ++i) {
8+
int temp = arr[i];
9+
int j = i;
10+
while (j >= gap && arr[j - gap] > temp) {
11+
arr[j] = arr[j - gap];
12+
j -= gap;
13+
}
14+
arr[j] = temp;
15+
}
16+
}
17+
}
18+
19+
int main() {
20+
ios::sync_with_stdio(false);
21+
cin.tie(nullptr);
22+
23+
vector<int> a = {170, 45, 75, 90, 802, 24, 2, 66};
24+
25+
shellSort(a);
26+
27+
for (int x : a) cout << x << ' ';
28+
cout << '\n';
29+
return 0;
30+
}

Shell_Sort

83.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)