Shell 选择排序
2024-10-20 09:24:18
举例
#!/bin/bash
echo "please input a number list:"
read -a arrs
for((i=0;i<${#arrs[@]};i++))
{
mindex=i;
for((j=i+1;j<${#arrs[@]};j++))
{
if [[ ${arrs[j]} -lt ${arrs[mindex]} ]];then
mindex=j;
fi
}
tmp=${arrs[i]}
arrs[i]=${arrs[mindex]}
arrs[mindex]=$tmp
}
echo "result:"
echo ${arrs[@]}
运行结果
please input a number list:
5 9 3 4 7 6
result:
3 4 5 6 7 9
最新文章
- 存储程序(2)——MYSQL
- 实战手记:让百万级数据瞬间导入SQL Server
- 联想 thinkpad fn键关闭,优化使用
- HTML练习----注册界面
- shell编程基础(4)case 与 function
- 设计模式------PROTOTYPE(原型),TEMPLATE(模板)
- Effective Java2读书笔记-类和接口(五)
- python正则表达式练习篇
- Java 抽象工厂模式
- highcharts第一篇---简介和使用
- 【转】CXF+Spring+Eclipse简明示例
- Unable to update index for central
- Using variables inside Postman and Collection Runner
- Django By Example 总结
- X级联动
- python--使用队列结构来模拟烫手山芋的游戏
- Linux中配置别名
- UVA1626 - Brackets sequence(区间DP--括号匹配+递归打印)
- js 获取浏览器/网页宽度高度整理
- SPL之Iterator和ArrayAccess的结合使用