Linux 脚本:冒泡排序

#!/bin/bash

arr=(3 2 5 4 1)

len=${#arr[@]}

for i in $(seq 1 $len) ; do
        index=$(($len - $i - 1))
        for j in $(seq 0 $index) ; do
                if [[ ${arr[j]} > ${arr[j+1]} ]]; then
                        tmp=${arr[j]}
                        arr[j]=${arr[j+1]}
                        arr[j+1]=$tmp
                fi
        done

done

echo ${arr[@]}

上一篇:RNA-seq | scRNA-seq | fancy分析工具


下一篇:2021-05-06