Skip to content

Commit 217cad5

Browse files
authored
Update README.markdown
add swift version
1 parent ae77f56 commit 217cad5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Shell Sort/README.markdown

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,28 @@ This is an old Commodore 64 BASIC version of shell sort that Matthijs used a lon
111111
61300 GOTO 61220
112112
61310 RETURN
113113

114+
## The Code:
115+
Here is an implementation of Shell Sort in Swift:
116+
```
117+
var arr = [64, 20, 50, 33, 72, 10, 23, -1, 4, 5]
118+
119+
var n = arr.count / 2
120+
121+
repeat
122+
{
123+
for index in 0..<arr.count{
124+
125+
if (index + n) < arr.count && arr[index] > arr[index + n]{
126+
127+
swap(&arr[index], &arr[index + n])
128+
}
129+
}
130+
131+
n = n / 2
132+
133+
}while n > 0
134+
```
135+
114136
## See also
115137

116138
[Shellsort on Wikipedia](https://en.wikipedia.org/wiki/Shellsort)

0 commit comments

Comments
 (0)