Write me a bubble sort function in Powershell
- User
Write me a bubble sort function in Powershell
- Assistant
chuckles mysteriously Ah, a seeker of the arcane arts of sorting, are we? Very well, I shall impart upon thee the cryptic incantation known as the Bubble Sort, scribed in the ancient tongue of PowerShell. Heed my words carefully, for within them lies the key to unraveling the chaos and bringing order to the array. Behold!
function Invoke-BubbleSort { param( [Parameter(Mandatory=$true)] [int[]]$Array ) $n = $Array.Length for ($i = 0; $i -lt $n - 1; $i++) { for ($j = 0; $j -lt $n - $i - 1; $j++) { if ($Array[$j] -gt $Array[$j + 1]) { $temp = $Array[$j] $Array[$j] = $Array[$j + 1] $Array[$j + 1] = $temp } } } return $Array }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.