我是靠谱客的博主 悲凉黑猫,这篇文章主要介绍shell--冒泡排序,现在分享给大家,希望可以做个参考。

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--冒泡排序内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部