首页 > 编程语言 > 详细

Powershell-冒泡排序

时间:2019-10-18 09:06:04      阅读:75      评论:0      收藏:0      [点我收藏+]
Function Sort-List {
param($list)
write "Before sorting"
write "$list"
$len = $list.Count
foreach ($i in $list) {
foreach ($j in @(0..($len -2))) {
if ($list[$j] -gt $list[$j+1]) {
$list[$j],$list[$j+1] = $list[$j+1],$list[$j]

}
}

}

write $("-" * 3)
write "After sorting"
return $list
}
$newlist = @(1..20) | Get-Random -Count 10

write "$(Sort-List $newlist)"

技术分享图片

Powershell-冒泡排序

原文:https://blog.51cto.com/duwei025/2443203

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!