El siguiente código trata del método de ordenamiento por inserción binaria en bash:
#!/bin/bash function insercionbinaria { lista=$1 tam=${#lista[@]} for i in $(seq 1 $[$tam-1]) ; do aus=${lista[$i]} izq=0; der=$[$i-1] while [ $izq -le $der ] ; do m=$[$[$izq+$der]/2] if [ $aus -lt ${lista[$m]} ] ; then der=$[$m-1] else izq=$[$m+1] fi done j=$[$i-1] while [ $j -ge $izq ] ; do lista[$[$j+1]]=${lista[$j]} j=$[$j-1] done lista[$izq]=$aus done } lista=(5 4 3 2 1) insercionbinaria $lista for i in ${lista[@]};do echo $i; done
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?