shell之冒泡排序
#冒泡排序
function bubble(){
array=(12 23 1 5)
for((i=0;i<${#array[*]}-1;i++))
do
for((j=0;j<${#array[*]}-i-1;j++))
do
if [ ${array[$j]} -gt ${array[`expr $j + 1`]} ]
then
temp=${array[$j]}
array[$j]=${array[`expr $j + 1`]}
array[`expr $j + 1`]=$temp
fi
done
done
for((i=0;i<${#array[*]};i++))
do
echo -n "${array[$i]} "
done
echo ""
}
#调用函数
bubble
运行结果
最后
以上就是悲凉黑猫最近收集整理的关于shell--冒泡排序的全部内容,更多相关shell--冒泡排序内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复