Powershell-冒泡排序

  • 来源:网络
  • 更新日期:2020-07-13

摘要:系统运维 Function Sort-List {param($list)write "Before sorting"write "$list"$len = $list.Countforeach ($i in $list) {foreach (

系统运维

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)"

新网虚拟主机