Skip to content

Commit 1d9710c

Browse files
committed
Adding partial shell-sort
1 parent c758641 commit 1d9710c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
items=("$@")
4+
length=${#items[@]}
5+
6+
major_step_index=$(( length / 2 ))
7+
8+
while (( major_step_index > 0 )); do
9+
for i in $( seq 0 major_step_index); do
10+
11+
for j in $( seq $(( i + major_step_index)) length major_step_index ); do
12+
current=$items[j]
13+
inner_step_index=$j
14+
15+
while (( inner_step_index >= major_step_index && items[(( inner_step_index - major_step_index ))] > current )); do
16+
items[$inner_step_index]=$items[(( inner_step_index - manjor_step_index ))]
17+
inner_step_index=(( inner_step_index - major_step_index ))
18+
done
19+
20+
items[$inner_step_index]=$current
21+
done
22+
23+
major_slice_index=(( major_step_index / 2))
24+
done
25+
done
26+
27+
28+
echo ${ items[@] }

0 commit comments

Comments
 (0)