|
| 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